Skip to content

Comment on Why OCaml, Why Now?parent

Comments

You may be confused by the fact that the type system will notice the equivalence of two types if the implementations of both are public eg

    module M = 
    struct
       type newtons = int
       let inc some_newtons = some_newtons + 1
    end :
    sig
       type newtons = int
       val inc : newtons -> newtons
    end

    M.inc 1 (* this works *)

    module M = 
    struct
       type newtons = int
       let inc some_newtons = some_newtons + 1
       let in_newtons x = x 
    end :
    sig 
       type newtons
       val inc : newtons -> newtons
       val in_newtons : int -> newtons
    end

    M.inc 1 (* type error *)
    M.inc (in_newtons 1) (* this works *)
The use of hidden types in OCaml gives far better control over encapsulation and implementation hiding than any over language I've used.
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.