* [Caml-list]
[not found] <20150821100011.4BF127F0D7@sympa.inria.fr>
@ 2015-08-21 12:28 ` Nils Becker
2015-08-21 12:39 ` [Caml-list] fa.caml google group not getting updates Nils Becker
1 sibling, 0 replies; 2+ messages in thread
From: Nils Becker @ 2015-08-21 12:28 UTC (permalink / raw)
To: caml-list
hi,
> > - Local opens are somewhat of an anti-pattern in OCaml, because they're
> > usually used in places where you have the same names defined in
> > multiple modules:
>
> While this is certainly a very popular use case in particular when
> dealing with operators, I find myself using the local 'let open' form
> very often in other contexts. In fact, I don't ever seem to find myself
> using it for redefining identifiers.
as another data point: i do the same. a typical function definition would be
let process_list list =
let open List in
list
|> map fun1
|> map2 fun2 another_list
|> iter fun3
basically whenever i can save more than 3 List. qualifiers in the body of a short function where the context is clear, i will do it. i don't see where the problem is with this usage; the standard modules i open are not subject to a lot of change. i think the readability gain is worth it.
>> (** Rotation on the vect(x,y) plane with an angle t
>> precondition: x and y are orthonormal *)
>> let rotation (x,y) t v = let open V in
>> v
>> + R.( ( cos t - 1. ) * (v|*|x) - sin t * (v|*|y) ) * x
>> + R.( sin t * (v|*|x) + ( cos t - 1. ) * (v|*|y) ) * y
+1. this is the kind of code that i would like to write as readable as possible with a short local open. it's basically a remedy for not having operator overloading.
> - In the absence of Modular Implicits, as Petter mentioned, it would be
> nice to have the warnings/potential errors only generated when the same
> names have the same types. In case of different types with the same name,
> the type system should take care of any issues.
this sounds like an elegant way to allow freedom of shadowing while keeping bugs under control.
another maybe trivial point: there are larger libraries that are designed to be opened destructively (Batteries etc); if the warning policy is changed in the same way for short and long opens, it should remain possible to do open! Batteries without a warning.
^ permalink raw reply [flat|nested] 2+ messages in thread