Skip to content

Instantly share code, notes, and snippets.

@sleexyz
Created August 16, 2016 05:34
Show Gist options
  • Save sleexyz/9a901e8b208e200bf25dbc3005fbce92 to your computer and use it in GitHub Desktop.
Save sleexyz/9a901e8b208e200bf25dbc3005fbce92 to your computer and use it in GitHub Desktop.
signature MONOID =
sig
type t
val append : t * t -> t
val zero : t
end
structure Additive =
struct
type t = int
val append = (fn (x, y) => x + y)
val zero = 0
end
structure Multiplicative =
struct
type t = int
val append = (fn (x, y) => x * y)
val zero = 1
end
functor Action (M : MONOID) : MONOID =
struct
type t = M.t -> M.t
val append = fn (f, g) => fn x => f (g (x))
val zero = fn (x) => x
end
structure AdditiveAction = Action(Additive)
val foo = Additive.zero + Multiplicative.zero (* val foo = 1 *)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment