Ocaml Log - Haskell Typeclasses in Ocaml

Posted on December 11, 2018

There are many articles explaining the things I’m about to log about. This is just my personal take and understanding on the subject.

I think this is how Haskell Typeclasses are transposed in Ocaml.

The most common data types I can think of is the Maybe data type from Haskell or the option in Ocaml. These data types are how these languages the possibility of null. These data types are going to prevent us from encoutering NullReferenceException like in other languages.

Maybe and Option instance of the Functor typeclass.

In Action

In ghci

The main difference here is I have to specify which fmap I have to use because Ocaml’s typesystem is not as powerful as Haskell’s where it will immediately determine which fmap to use just based on the type.

Bucklescript will represent Some as an array.