Skip to content

Instantly share code, notes, and snippets.

@yonta
Last active March 24, 2020 13:11
Show Gist options
  • Save yonta/08abe597c8a8ed1620de0ef88ec68816 to your computer and use it in GitHub Desktop.
Save yonta/08abe597c8a8ed1620de0ef88ec68816 to your computer and use it in GitHub Desktop.
signature SHOW =
sig
type t
val show : t -> string
end
structure ShowInt : SHOW where type t = int =
struct
type t = int
val show = Int.toString
end
structure ShowReal : SHOW where type t = real =
struct
type t = real
val show = Real.toString
end
(* with a functor *)
functor F (M : SHOW) = struct
val f = M.show
end
local
structure F_int = F (ShowInt)
structure F_real = F (ShowReal)
in
val x = (F_int.f 42, F_real.f 3.14)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment