Skip to content

Instantly share code, notes, and snippets.

@puffnfresh
Created May 2, 2012 08:14
Show Gist options
  • Save puffnfresh/2574986 to your computer and use it in GitHub Desktop.
Save puffnfresh/2574986 to your computer and use it in GitHub Desktop.
Roy monoid type-class with JS output
var stringMonoid = {
"append": function(x, y) {
return x + y;
},
"empty": ""
};
console.log(stringMonoid.append(stringMonoid.append("Hello!", stringMonoid.empty), stringMonoid.empty));
var f = function(Monoid, x) {
return Monoid.append(Monoid.empty, x);
};
var g = function(Monoid, x) {
return f(Monoid, x);
};
console.log(g(stringMonoid, "TEST"));
//@ sourceMappingURL=monoid.js.map
typeclass Monoid #a {
append: Function(#a, #a, #a)
empty: #a
}
instance stringMonoid = Monoid String {
append: \x y -> x ++ y
empty: ""
}
console.log (append (append "Hello!" empty) empty)
let f x = append empty x
let g x = f x
console.log (g "TEST")
@jedws
Copy link

jedws commented May 2, 2012

zero!

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