Skip to content

Instantly share code, notes, and snippets.

@kevroletin
Created March 22, 2019 06:53
Show Gist options
  • Save kevroletin/18f682bc0f89508ad6efcb3262ef03d4 to your computer and use it in GitHub Desktop.
Save kevroletin/18f682bc0f89508ad6efcb3262ef03d4 to your computer and use it in GitHub Desktop.
module type COUNTER = sig
val inc : unit -> int
end
;;
module CounterImpl = struct
let data = ref 0
let inc () = data := !data + 1; !data
end
;;
module CounterImpl2 = struct
include CounterImpl
end;;
module Counter : COUNTER = CounterImpl
;;
let counter = (module CounterImpl : COUNTER)
;;
module Counter2 = (val counter : COUNTER)
;;
(* type counter = { mutable value : int };;
*
* module type Counter = sig
* type t
*
* val inc : t -> unit
* val dec : t -> unit
* val get : t -> int
* end;;
*
* module CounterImpl : (Counter with type t = counter) = struct
* type t = counter
*
* let inc c = c.value <- c.value + 1
* let dec c = c.value <- c.value - 1
* let get c = c.value
* end;; *)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment