unisonweb / unison

A friendly programming language from the future
https://unison-lang.org
Other
5.66k stars 266 forks source link

Allow empty cases #3851

Open ChrisPenner opened 1 year ago

ChrisPenner commented 1 year ago

Now that we have pattern-match checking we don't have a reasonable way to handle type with no constructors.

For example if I have an empty error type that I need to handle:

type MyErrors = 

handleMyErrors : MyErrors -> Text
handleMyErrors = cases

This fails to compile:

    😶

    I expected some patterns after a match / with or cases but I didn't find any.

        4 | handleMyErrors = cases

I can't even use absurd here because it's a unique type. So the only option is "bug", but this isn't great because it means Unison won't warn me that I have unhandled cases if I add a new error case in the future.

Instead we should consider just allowing empty case statements for types with no constructors (this is what Haskell does)

aryairani commented 1 year ago

Thanks for reporting, we could do this during a cooldown week if desired; otherwise feels low priority.

aryairani commented 6 months ago

@tstat What would need to happen here?

tstat commented 6 months ago

I expect the pattern match coverage checker to handle empty cases fine as is. I assume that error is from the parser, so maybe all that needs changing is the parser.