Created
August 26, 2012 08:55
-
-
Save lyricallogical/3476389 to your computer and use it in GitHub Desktop.
なんか rank2-polymorphism と existential type が欲しかったけど無かったので first-class 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
type 'a node = | |
| A: int -> int node | |
| B: string -> string node | |
module type Exists = sig | |
type t | |
val ret: t node | |
end | |
module type PolyFun = sig | |
val f: 'a node -> (module Exists) | |
end | |
let f: type a. a node -> (module Exists) = function | |
| A _ -> let module Ret = struct type t = string let ret = B "hoge" end in (module Ret) | |
| B _ -> let module Ret = struct type t = int let ret = A 0 end in (module Ret) | |
let g: type a. a node -> (module PolyFun) -> (module Exists) = fun n pf -> | |
let module PF = (val pf: PolyFun) in | |
PF.f n | |
let result = g (A 1) (module struct let f = f end: PolyFun) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment