Advertisement
Guest User

Ocaml version of Haskell's newtype?

a guest
Nov 1st, 2014
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.42 KB | None | 0 0
  1. --Haskell version
  2. newtype Id1 = Id1 {unId1 :: Int}
  3. newtype Id2 = Id2 {unId2 :: Int}
  4.  
  5.  
  6. (* Ocaml version *)
  7. module Id1 : sig
  8.   type t
  9.   val of_int : int -> t
  10.   val to_int : t -> int
  11. end = struct
  12.   type t = int
  13.   let of_int = ident
  14.   let to_int = ident
  15. end
  16.  
  17. module Id2 : sig
  18.   type t
  19.   val of_int : int -> t
  20.   val to_int : t -> int
  21. end = struct
  22.   type t = int
  23.   let of_int = ident
  24.   let to_int = ident
  25. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement