Created
September 15, 2014 16:12
-
-
Save komamitsu/d78249b9a32c3979e94a to your computer and use it in GitHub Desktop.
Practice of First-class module (generate new module)
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 Bumpable = sig | |
type t | |
val bump : t -> t | |
end;; | |
module type Bumpable = sig type t val bump : t -> t end | |
# module Int_bumper = struct | |
type t = int | |
let bump n = n + 1 | |
end;; | |
module Int_bumper : sig type t = int val bump : t -> t end | |
# let int_bumper = (module Int_bumper : Bumpable with type t = int);; | |
val int_bumper : (module Bumpable with type t = int) = <module> | |
# let create_newbump (type a) (module B : Bumpable with type t = a) = | |
(module struct | |
type t = B.t | |
let bump n = B.bump (B.bump n) | |
end : Bumpable with type t = a) | |
;; | |
val create_newbump : (module Bumpable with type t = 'a) -> (module Bumpable with type t = 'a) = <fun> | |
# let nb = create_newbump int_bumper;; | |
val nb : (module Bumpable with type t = int) = <module> | |
# module NB = (val nb : Bumpable with type t = int);; | |
module NB : sig type t = int val bump : t -> t end | |
# NB.bump 3;; | |
- : int = 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment