Created
May 2, 2012 08:14
-
-
Save puffnfresh/2574986 to your computer and use it in GitHub Desktop.
Roy monoid type-class with JS output
This file contains 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
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 |
This file contains 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
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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
zero!