Skip to content

Instantly share code, notes, and snippets.

@Pitometsu
Created August 21, 2019 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pitometsu/a8e1ae10f3f48cd6b47df5013b49c33e to your computer and use it in GitHub Desktop.
Save Pitometsu/a8e1ae10f3f48cd6b47df5013b49c33e to your computer and use it in GitHub Desktop.
first-class module dependent types
let f (type k) : x:((module Caml.Map.S with type key = k) as 'a) -> y:'a -> z:k -> unit = fun ~x:(_) ~y:(_) ~z:(_) -> ();;
val f :
x:(module Core.Caml.Map.S with type key = 'a) ->
y:(module Core.Caml.Map.S with type key = 'a) -> z:'a -> unit = <fun>
@Pitometsu
Copy link
Author

let get (type a) ~from:((module F) : (module Caml.Map.S)) : unit = let to_ : a F.t = failwith "undefined" in ignore to_;;
val get : from:(module Core.Caml.Map.S) -> unit = <fun>

But:

let get (type a) ~from:((module F) : (module Caml.Map.S)) ~to_:(m : a F.t) : unit = ();;
Error: This pattern matches values of type a F.t
       but a pattern was expected which matches values of type 'a
       The type constructor F.t would escape its scope

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment