Created
March 22, 2019 06:53
-
-
Save kevroletin/18f682bc0f89508ad6efcb3262ef03d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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