Last active
September 17, 2016 09:59
-
-
Save zkat/9d4035b2ccef4394bb9d6e64e426bba4 to your computer and use it in GitHub Desktop.
Sketched out idea for extending protocols with additional protocol constraints
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
const Eq = protocol(['a', 'b'], { | |
eq: ['a', 'b'], | |
neq: ['a', 'b'] | |
}) | |
const Ord = protocol(Eq('a', 'b'), ['a', 'b'], { | |
gt: ['a', 'b'], | |
lt: ['a', 'b'] | |
}) | |
Ord([String, String], { | |
gt (a, b) { return a > b } | |
lt (a, b) { return a < b } | |
}) // => ERROR: No implementation for extended protocol defined for [String, String] | |
// Multiple constraints, no genfuns, Applicative and Chain implementations directly in Monad | |
const Monad = protocol([Applicative, Chain], [], { | |
// fantasy-land does not define any methods on Monad -- just the inheritance constraints | |
}) | |
Applicative(Parser, { | |
of() { ... } | |
}) | |
Monad(Parser, {}) // => Error | |
Chain(Parser, { | |
chain() { ... } | |
}) | |
Monad(Parser, {}) | |
Protocol.hasImpl(Monad, Parser) // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment