Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicity mention missing constructors of matchWith patterns #138

Closed
jreut opened this issue Jul 10, 2017 · 2 comments
Closed

Explicity mention missing constructors of matchWith patterns #138

jreut opened this issue Jul 10, 2017 · 2 comments

Comments

@jreut
Copy link

jreut commented Jul 10, 2017

When writing pattern-matching functions using matchWith, it is possible to not cover all the variants of a union. Since of course we cannot statically verify all cases of a pattern match are covered, this error occurs at runtime. Currently, attempting to match on a missing variant results in a generic error. I think it would be useful to have a more specific error that tells us what variant we need to add to the matchWith pattern.

I'm more than happy to submit a pull request with this small change if you think it would be useful!

Steps to reproduce

import { union } from 'folktale/adt/union'
const Operation = union({
  Add: (a, b) => ({ a, b }),
  Subtract: (a, b) => ({ a, b }),
})

// evaluate : Operation -> Int
const evaluate = op => op.matchWith({
  Add: ({ a, b }) => a + b
  // Subtract not implemented!
})

evaluate(Operation.Subtract(3, 4))

Expected behaviour

Error like Variant "Subtract" not covered in pattern

Observed behaviour

Error like TypeError: pattern[name] is not a function

Environment

Folktale v2.0.0-rc1

@robotlolita
Copy link
Member

Ah, I didn't realise the error was that bad. Yeah, we do need a better error message here.

@robotlolita
Copy link
Member

This has been released as folktale@2.3.0

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

No branches or pull requests

2 participants