Skip to content

Instantly share code, notes, and snippets.

@cemerick
Last active May 19, 2019 02:44
Show Gist options
  • Save cemerick/3d059e3e6021adc1255609762ccc1853 to your computer and use it in GitHub Desktop.
Save cemerick/3d059e3e6021adc1255609762ccc1853 to your computer and use it in GitHub Desktop.
type a = [ `A of int ]
type b = [ a | `B of int ]
let pair (a : a) (b : b) = ([a] :> b list) @ [b] (* works fine *)
module type Config = sig type t end
module type Box = sig
module C : Config
type t = { regions : C.t list }
val empty : t
val add : C.t -> t -> t
val get : t -> C.t list
end
module Box (C: Config) : Box with type C.t = C.t = struct
module C = C
type t = { regions : C.t list }
let empty = { regions = [] }
let add r box = { regions = r :: box.regions }
let get box = box.regions
end
module ABox = Box(struct type t = a end)
module BBox = Box(struct type t = b end)
(* Error: Type ABox.t is not a subtype of BBox.t *)
let join (abox : ABox.t) = BBox.get (abox :> BBox.t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment