Skip to content

Instantly share code, notes, and snippets.

@zkat
Last active September 17, 2016 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zkat/9d4035b2ccef4394bb9d6e64e426bba4 to your computer and use it in GitHub Desktop.
Save zkat/9d4035b2ccef4394bb9d6e64e426bba4 to your computer and use it in GitHub Desktop.
Sketched out idea for extending protocols with additional protocol constraints
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