Allow ScopedTypeVariables to refer to types #128
Conversation
|
I basically support this proposal, but starting with an intricate GADT example conceals the point. Please can we offer a series of examples, starting simple. For example (all assuming This is clearly fine. Both Now the kicker: If this was allowed One reason for making the change is that it's not really clear what being "bound to a type variable" means in the presence of type equalities. For example: Which of these should be accepted under the current rules? (SPJ says: I don't even know; I'd have to try it.) An advantage of the proposal is that such questions become irrelevant. ....You can add some more examples. Be sure to talk about repeated variables too! |
|
I also support this proposal. Another motivation that might be worth mentioning is the ability to bind large types to shorter variable names, such as in: f :: ReallyReallyReallyReallyLongTypeName -> T
f (x :: a) = ...
-- Instead of f (x :: ReallyReallyReallyReallyLongTypeName) |
|
What about this: Note: no type signature. This is rejected today, because |
|
Indeed, my branch accepts that code:
The proposal states that only because it is the smallest delta to the status quo. I am too typechecker ignorant to get this right on my own, so I will need your help. (Where “you” refers to the numerous hoards of type-checker hacker out there, not necessarily just Richard. There are legions of those, are there?) Shall we simply drop that sentence? |
|
I vote to drop that sentence, or for someone to explain what it means. |
and also mention that the current behavior about repeated type variables is unchanged.
Yes I think that sentence is probably nonsense |
|
Could you take advantage of the opportunity, and write as tight a spec for the new system as you can? Things specified by deltas from an ill-specified baseline are never satsifying. Just specify pattern type signatures ab-initio. In the light of this discussion doing so may not be hard. |
|
I also think this is a good idea. Oddly, I am pretty sure that type variables in patterns used to work as in the proposal some time ago, but I guess at some point they got switched to being universal?? We've had this feature for a long time in Cryptol, and I think it works pretty well. |
|
My request for a spec is answered by this paper: https://www.microsoft.com/en-us/research/publication/type-variables-patterns/. Have a look! |
|
Lovely. Is there a plan to implement appendix B? I for one would be happy to give up |
|
One step at a time. Let's do type applications in patterns first. |
|
Is this ready to submit to the committee now? |
|
Is there merit in bundling this with #126 and have just one proposal for the paper? But probably not, they are nicely orthogonal… Are you happy with the text? |
|
In the "specification" part, there is a reference to "the above sentence" which is unclear to me. The best referent seems to have two sentences. |
|
The paper mentions type lambdas as an alternative. But isn't there no conflict? Isn't this forward compatible with: singleton @b (x :: b) = x -- goodsingleton :: a -> [a]
singleton @b (x :: b) = x -- goodsingleton :: Show a => a -> [a]
singleton @b (x :: b) = x -- goodsingleton :: forall b. b ~ Int => Int -> [Int]
singleton @b (x :: b) = x -- goodsingleton :: Int -> [Int]
singleton @b (x :: b) = x -- bad, because there's explicitly no ∀ typesingleton :: a -> [a]
singleton @b (x :: c) = x
-- ^ bad, because cannot mix implicit (for `c`) and explicit (for `b`) Λ |
|
I've responded to #128 (comment) in #155. |
|
Haha, what timing! |
|
All the examples are pattern signatures within function binds. What about pattern binds? It is not clear to me. x :: a = 1 :: Int -- OK ?
f :: a -> a -- fresh or captured a?
f = idThe options I think make sense to me are
What worries me would be taking a turn from #228 and trying to allow x :: a = 1 :: Int
x' :: forall a. Num a => a = \ @c => 1 :: c
Just (y :: b) = Just (1 :: Int)
Just (y :: forall b. Num b => b) = Just $ \ @c => 1 :: cIn deference to future work on impredicative types, I only want the two |
Both before & after this proposal, pattern binds don't support scoped type variables.
Not OK as pattern binds don't support However, #228 reclassifies this as a nullary function bind, so it should be OK in the future. |
|
@int-index sorry lost internet so tardily edited the post above.
I believe you but the error messages make this rather confusing Prelude> (1 :: Int) = 1
<interactive>:8:2: error:
Illegal type signature: ‘Int’
Type signatures are only allowed in patterns with ScopedTypeVariablesIf we still had |
|
@int-index I'll take the second part back to a #228 modification. Thanks for clarifying exactly what this does. |
The proposal has been accepted; the following discussion is mostly of historic interest.
Rendered