Skip to content

Instantly share code, notes, and snippets.

@ramntry
Created December 1, 2014 15:39
Show Gist options
  • Save ramntry/91448cefe05fed73fc6a to your computer and use it in GitHub Desktop.
Save ramntry/91448cefe05fed73fc6a to your computer and use it in GitHub Desktop.
module type List = sig
type a
type t
val nil : t
val cons : a -> t -> t
val switch : (unit -> 'b) -> (a -> t -> 'b) -> t -> 'b
end
let to_string (type e) (type s) (module Impl : List with type a = e and type t = s) string_of_item l =
let rec inner ys =
Impl.switch
(fun () -> "")
(fun x xs -> string_of_item x ^ " " ^ inner xs)
ys
in
inner l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment