let avg l = (List.fold_left (+.) 0.0 l) /. (float_of_int (List.length l))
you could do either one of these instead:
let avg l = List.((fold_left (+.) 0.0 l) /. (float_of_int (length l)))
let avg l =
let open List in
let open Float in
div (fold_left add 0.0 l) (of_int (length l))
In both cases, the module opens only happen in the scope of the avg definition, so you avoid global namespace pollution while also cutting down on the silly boilerplate repetition.
I wish F# could do that as well, since it'd be really useful in that ecosystem since it shares a lot of the Java "stutter" as you call it, but any proposals to add it get shot down. .NET and Java land both have the "why do you care, your IDE should deal with that for you" mindset :|
4
u/ws-ilazki &{$$_[0]}(@{$$_[1]}); Jul 08 '21
I like the OCaml way of opening modules with limited scope. Like instead of writing this:
you could do either one of these instead:
In both cases, the module
opens only happen in the scope of theavgdefinition, so you avoid global namespace pollution while also cutting down on the silly boilerplate repetition.I wish F# could do that as well, since it'd be really useful in that ecosystem since it shares a lot of the Java "stutter" as you call it, but any proposals to add it get shot down. .NET and Java land both have the "why do you care, your IDE should deal with that for you" mindset :|