Skip to content

Instantly share code, notes, and snippets.

@Pitometsu
Created August 13, 2019 20:15
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/477c8a60a0c1f5e5732977b2656e8aea to your computer and use it in GitHub Desktop.
Save Pitometsu/477c8a60a0c1f5e5732977b2656e8aea to your computer and use it in GitHub Desktop.
Pass module's existential type to universal argument
module type S = sig
type t
val of_string : string -> t
val to_string : t -> string
end
let deser : 'a. (module S with type t = 'a) -> (_ -> 'a) * _ = fun m ->
let module M = (val m) in
M.(of_string, to_string)
(* Error:
* The type of this packed module contains variables:
* (module Convert.CONVERTER with type t = 'a0)
*)
@Pitometsu
Copy link
Author

Pitometsu commented Aug 13, 2019

Found the answer:

module type S = sig
  type t

  val of_string : string -> t
  val to_string : t -> string
end

type 'a c = (module S with type t = 'a)

let deser = fun (type a) ((module M) : a c) ->
  M.(of_string, to_string)

(* ==>
 *   val deser : 'a c -> (string -> 'a) * ('a -> string) = <fun>
 *)

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