Hacker News new | past | comments | ask | show | jobs | submit login

OCaml has first-class modules & functors (functions on modules). I can write something like:

  let f (type t) some_arg (module M : Stringable with type t = t) = M.to_string some_arg
This will have the type signature

  val f : 'a -> (module Stringable with type t = 'a) -> string
In this case the module type Stringable looks like:

  module type Stringable = sig
    type t
    val to_string : t -> string
Functors are just module types so can be used in the same way. Module types fit in as normal values, you don't have to pattern match on them. This works:

  let id x = x
  
  id (module Int)



Interesing; I've not used Ocaml much (mostly just reading, e.g. the Coq source), so I'm more familiar with StandardML's more verbose separation.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: