This post presents a quick translation of the haskell code of the article Typing Haskell in Haskell by Mark P. Jones to OCaml.
I did this translation to experiment with type-class capable type inference for my Photon compiler project. I decided upon OCaml because:
I share it because:
While I intend to rewrite this code completely from scratch in my project (indeed, my type system is not even the same as Haskell), I kept this translation nearly as close to the original as possible to:
One thing I changed is switching from monads to exceptions, as OCaml has no syntactic support for monads. I even used exceptions when I could have used the option
type for the same reason. Maybe
values in the haskell code are used monadically.
There are also some re-ordering, as OCaml process files linearly (i.e. values must be defined before being used). I even had to fuse sections 11.3 to 11.6 due to mutual recursion.
The type inference monad has been replaced by mutable state which is passed explicitely such that a function which had the haskell type
f :: SomeType -> TI OtherType
has the OCaml type
val f : ti -> someType -> otherType
Discussion