I wrote the following function while following Real World OCaml, which uses the Core library.
open Core.Core_list
open Core.Option
open Core.Std
open Re2
let getMaxFilename target =
let Ok pat = Regex.create "^.*(..)\\.txt$" in
Sys.ls_dir target |>
List.map ~f:(Regex.find_submatches pat) |>
List.filter ~f:is_ok |>
List.map ~f:(fun x -> ok_exn x |> Array.to_list |> (Fn.flip nth_exn) 1 |> fun x -> value_exn x) |>
List.reduce ~f:max
It looks messy to me since I have a lot of "opens" at the top and I have to name List, Array, Sys, Fn, and the other modules names in all the functions that I use. This is the "right" way to write OCaml? Is there a standard style that dispenses with these?
open Core,open Core.Stdand have fun - Kakaduopen Coreandopen Core.Std, but I do not get access to functions likeflipornth. Sounds like I still need to name many of the modules. Is this the right way to write Ocaml code? - AnaList.nthverbosely to be sure from what module the function is. Of course, we should find a way to keep balance, between readability and verbosity. - Kakadusmall tipthan afull answer. - Kakadu