Recently I am reading some functional programming books involving Haskell.
It seems Haskell quite fancies “modular programs”, for example,
f :: (Integer,Integer) -> Integer
f = sum . map sq . filter . odd . between
even though the same function can be written like
f' (m, n) = go m
where go m | m > n = 0
| otherwise = go (m + 1) + if odd m then sq m else 0
Also “fusion laws” are quite popular and used (http://www.cs.ox.ac.uk/ralf.hinze/publications/IFL10.pdf)
I am not an OCaml expert, but I would use fold_left
or fold_right
if possible and easy and efficient (for example, anyway I have to scan the whole list and won't stop in the middle).
However, at most of the time, I will write explicit recursive code using “pattern matching”.
Also I read quite some OCaml projects in github and explicit recursive seems are very usual.
In addition, I never heard of fusion law for OCaml.
My questions are
- Is OCaml the same that it prefer modular programs like shown above in Haskell?
- Does OCaml also have fusion laws?
- If I want to be an OCaml professional, should I really care or learn from Haskell's fusion laws?