-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Correlating match types with pattern matching expressions #6709
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
Comments
Using enum cases isn't going to work here: the companion objects of enums have an apply method whose result type is the type of the enum, so Anyway, if we do this replacement in your code, then we get the following errors: 22 | case Zero => new Odd(Zero)
| ^^^^^^^^^^^^^
| Found: Main.BinNat.Odd[Main.BinNat]
| Required: Main.Inc[Main.BinNat(b)]
23 | case Odd(n) => new Even(n)
| ^^^^^^^^^^^
| Found: Main.BinNat.Even[N$1]
| Required: Main.Inc[Main.BinNat(b)]
|
| where: N$1 is a type in method inc with bounds <: Main.BinNat
26 | new Odd(inc(n))
| ^^^^^^^^^^^^^^^
| Found: Main.BinNat.Odd[Main.BinNat]
| Required: Main.Inc[Main.BinNat(b)] So the compiler isn't able to figure out that |
@smarter Not by itself, no, even if we extend it. We could (and at one point wanted to) allow adding GADT constraints to singleton types such as I'd say the final missing piece is that we should redefine To sum up, we need:
|
Actually: @OlivierBlanvillain, do you see an alternative way forward with the "matching cases" logic that you at one point proposed for typing functions returning match types? |
I've been trying to use match types to implement a type-level binary nat type.
Here is the code I would ideally like to work:
The error message I get is:
I have tried several different variants (using manual sealed trait/case classes, matching on
_: Zero.type
, explicitly adding type annotations in thedef inc
method... each seemed to trigger different errors and I couldn't find any that worked.expectation
I'd like it to compile, or suggest a better action to take in the error message
The text was updated successfully, but these errors were encountered: