Created
August 16, 2016 05:34
-
-
Save sleexyz/9a901e8b208e200bf25dbc3005fbce92 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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