A port of the library described in this 2006 paper from Haskell to OCaml. This was ill-advised, because I didn't know Haskell or OCaml. I thought this would be a good opportunity to get comfortable with both. Also, the actual library has got some pretty interesting concepts.
I've translated the core of the module, Probability.hs (from the original 2006 version) to OCaml.
A lot of the time, this felt like trying to fit a round peg into a square hole:
-
Type Definitions:
- Haskell uses
newtypeforProbability, while OCaml usestype. - Haskell defines
Distas anewtype, whereas OCaml uses a regular type definition.
- Haskell uses
-
Monad and Functor Instances:
- Haskell defines
MonadandMonadPlusinstances forDist. - OCaml uses functions like
bindandmplusto achieve similar functionality.
- Haskell defines
-
Random Values:
- Haskell uses the
IOmonad for random values (Rtype). - OCaml uses a function type
unit -> 'afor random values (randomtype).
- Haskell uses the
-
Pretty Printing:
- Haskell uses the
Showtypeclass for pretty printing. - OCaml uses functions like
show_distfor pretty printing.
- Haskell uses the
-
Expected Value Calculation:
- Haskell uses the
Expectedtypeclass. - OCaml uses a module type
Expectedand functors to achieve similar functionality.
- Haskell uses the
-
Iteration and Simulation:
- Haskell uses the
IterateandSimtypeclasses. - OCaml uses modules and functors to define similar behavior.
- Haskell uses the
-
Conditional Probability:
- Haskell uses the
|||operator for filtering distributions. - OCaml uses the
|||operator for similar functionality but implemented differently.
- Haskell uses the
-
Randomized Generators:
- Haskell defines
RChangeandRTranstypes for random changes and transitions. - OCaml defines similar types but uses different naming conventions and implementations.
- Haskell defines