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
Support GADTs in or-patterns #5736
Comments
Comment author: @garrigue This one is a long-term goal. |
Comment author: @xavierleroy Moving to "later" based on @garrigue's comment. |
This has been implemented in #2110, and the first version of the |
This hasn't quite been implemented: after #2110 you don't have the information that But I agree that the example given here is now accepted by the compiler indeed. |
I see --- so the following example is not yet allowed: let zero : type t. t gadt -> t = function
| Float _ | Float2 _ -> 0.0
| Int _ -> 0 @trefis: feel free to reopen if you think this is the best place to track that work. |
Will it ever be possible to pattern match by the type rather than the constructor? eg in pseudo-OCaml:
|
Your syntax is confusing. let zero : type t. t gadt -> t = function
| (_ : float gadt) -> 0.0
| Int _ -> 0 expecting that it would automatically expand |
If I follow, your idea is that (Note: we already have logic in place to explode wildcard patterns in situations that are different but related -- when checking refutation clauses.) |
I've longed for such a feature several time. Simple syntax proposition: extend |
Original bug ID: 5736
Reporter: omion
Assigned to: @garrigue
Status: confirmed (set by @garrigue on 2012-08-22T23:27:03Z)
Resolution: open
Priority: normal
Severity: feature
Version: 4.00.0
Target version: later
Category: typing
Related to: #7319
Child of: #5998
Monitored by: @hcarty
Bug description
Currently, if you have a GADT with multiple branches sharing the same type, eg:
then try to use Float and Float2 in one branch of a function:
this will not pass the type checker, even though Float and Float2 have the same type:
You would have to have each variant:
or, matching with the default "_" will work since it's not an or-pattern, but this only works well if there is only one type in the GADT that has the problem:
It would be handy to be able to combine the branches for GADT constructors that refer to the same types.
The text was updated successfully, but these errors were encountered: