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
Ambiguous Type per-signature pragma #232
Conversation
I'm in strong support of this well-written proposal, but please permit me to offer some suggestions:
Though we can't use this today, with my "type-lambda" proposal, we could write
and then call
Thanks for writing this up @AntC2. |
Same goes for |
I echo @goldfirere's support, thanks @AntC2!
|
Yes. My chief concern is with sourcecode tooling and people importing this program as a package: they'll need to know they're in for
Actually no: if an instance is marked |
Ah, OK. I was thinking
OK fair point re "and then stop". I was trying to keep it simple for the implementer.
Yes that was my thinking in the Interactions section "migration path". Without saying it out loud for fear of upsetting @pplication-aholics, who I expected to say this:
That only makes sense if we don't deprecate
;-) That's the current behaviour with
I'm happy to take a recommendation. Error or only warning? How easy to implement? |
I'm definitely in support of controlling the scope of In the past, there have been many proposals to allow controlling warnings on a per-identifier basis, such as this GHC issue suggesting an Granted,
It is worth noting that this specification prevents the use of
Compiling this without
However, since
Having written all of this up, I realize that it's somewhat unfair to oppose this proposal (which, by all accounts, is very well motivated and clear in its scope) on the grounds that it should be superseded by a more ambitious proposal without a clear design. In that case, I suppose I could live with my idea simply being mentioned as an alternative. If that is what is decided, however, I would like to see the proposal amended to mention the following:
|
Thanks @RyanGlScott, re your specific point
Yes, @goldfirere said the same. That's exposing my paucity of imagining how devious I wanted to narrow the scope because there's many causes/places GHC says As audience for this change I have in mind not GHC HQ/the people who typically respond to these proposals, but the people who ask questions on StackOverflow/are confused and hoodwinked by GHC saying The sort of people who say "I'm far from an expert on type inference, so I can't really offer a As to your more general (and frankly rather ineffable point) about "delimiting regions of code" ... Thanks for drawing attention to #602. I've put a response on there, in general (but not ineffably general) terms.
That's right. It's suppressing what would otherwise be a rejection/error, not a warning. Furthermore, it exhibits what I might call 'action at a distance': we are in effect not suppressing an error check at the definition site so much as mandating The more I thought about #602, the more it seemed to me there were plenty of examples of this 'action at a distance' such that "regions of code" is not a helpful delimitation. (Try arriving at a sensible delimitation of overlapping instances in terms of "regions of code".) Whether or not something more effable can be rescued from #602, currently it seems to me poorly argued, unsupported by use cases, and just plain wrong as stated. I see no merit. Also |
Ah, to sweep up a couple of @RyanGlScott's other examples (seeking feedback whether this makes sense)
With
? If Following the "wherever
(Whatever it is you're trying to do with
Sorry, don't follow: if there's no signature, there can't be a tyvar to be ambiguous. (If the function's type is given via pattern signatures/term annotations, the "wherever |
Thanks @goldfirere , @RyanGlScott. I've incorp'd your feedback as follows:
I'm surprised feedback on this has dried up so quickly. I'll be ready to pass for committee consideration within a couple of days, unless there's violent disagreement. (At that point, I'll make more executive decisions re the 'Unresolved questions') |
Thanks for this updates. I'm in support. |
6b33e58
to
e7fdbc7
Compare
…s resolved; formatting.
Hi @nomeata, please submit this for Committee discussion. No further feedback received on the 'Unresolved questions', so I've frozen in a resolution for each, but left them visible for discussion. No strong objections from anybody, but OTOH very few explicitly supporting. There was another example on StackOverflow this month of somebody writing a class with an ambiguous method signature; getting the rejection message |
I will be shepherding this proposal. Before making my recommendation (which is expected to be "accept"), I would like @AntC2 to clarify a few issues:
Thanks! |
Thanks @goldfirere, before I clarify the proposal could I clarify ...
I'll clarify the wording to say that if |
It sounds like you've clarified on your own. :) You're zeroing in on exactly the changes I wanted. Thanks! |
…gration path for modules vs future for GHC
OK done. Over to @goldfirere ... |
This proposal will now be discussed by the committee. We welcome all authors to join the discussion, but kindly ask others to refrain from posting. Summary
Recommendation I recommend acceptance. I am wholly in support of points (1) and (3) above, and weakly in support of (2). Module-wide language settings should either be impossible (or very difficult) to specify locally, or should be agreed to be benign. My lukewarm support of (2) is that it's a bit annoying for users to have to specify both I look forward to your discussion, committee. As usual, silence will be taken as agreement. |
Done. See Changelog. Another month, another confused learner bamboozled by GHC's error message into unnecessary |
Sorry to be so late to the discussion. I also like the direction of this proposal, but have a couple questions about the specifics.
|
The proposal is to touch everywhere that's currently touched by
(To be precise, with You might want to argue ambiguous expression ascriptions shouldn't be allowed. Take that up with the original author of the extension. That'd be a different proposal (because it risks breaking currently accepted code).
@simonpj gets it. You seem to be of the brutalist school of software evolution. |
AllowAmbiguousTypes allows any user-written type in the module to be ambiguous. The whole point of this proposal is that that’s painting with far too large a brush. So I think this is a natural time for us to ask where desired ambiguity arises.
The main instance I’m aware of is in class methods that are meant to be @pplied to the type rather than a value. It’s hard to imagine a case where I want an ambiguous type ascribed to an arbitrary expression. We’re already at the use-site, which means the ambiguity must be resolved immediately, so why not just resolve it in the ascribed type?
If we disallow ambiguity in ascriptions to expressions (and type applications) we could use named pragmas instead of positional pragmas, which would be a win for readability IMO. This is not a major issue, but it does seem like an opportunity to clean up a bit more than the current proposal does.
Regarding the warning, I’m one of those people who likes to enable -Werror in CI, so Simon and my proposed migrations would be functionally equivalent for me, it would all have to happen in a single PR. Does that make me a brutalist? :)
…Sent from my iPhone
On Aug 1, 2019, at 23:43, AntC ***@***.***> wrote:
@gridaphobe 1. ... I haven't seen an argument for allowing ambiguous types in ascriptions to arbitrary expressions.
The proposal is to touch everywhere that's currently touched by AllowAmbiguousTypes. Currently this is rejected unless you set that extension
x = undefined :: (Num a, Ord b) => a
(To be precise, with AllowAmbiguousTypes set, that's rejected for other reasons ;-). And introducing TypeApplications to fix them seems to kick out some weird kind errors GHC 8.4.4.)
You might want to argue ambiguous expression ascriptions shouldn't be allowed. Take that up with the original author of the extension. That'd be a different proposal.
The -Wambiguous-types warning seems unnecessary to me. ...
@simonpj gets it. You seem to be of the brutalist school of software evolution.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
But your point regarding the warning is well-taken, we should accommodate people who want a more gradual migration.
…Sent from my iPhone
On Aug 1, 2019, at 23:43, AntC ***@***.***> wrote:
@gridaphobe 1. ... I haven't seen an argument for allowing ambiguous types in ascriptions to arbitrary expressions.
The proposal is to touch everywhere that's currently touched by AllowAmbiguousTypes. Currently this is rejected unless you set that extension
x = undefined :: (Num a, Ord b) => a
(To be precise, with AllowAmbiguousTypes set, that's rejected for other reasons ;-). And introducing TypeApplications to fix them seems to kick out some weird kind errors GHC 8.4.4.)
You might want to argue ambiguous expression ascriptions shouldn't be allowed. Take that up with the original author of the extension. That'd be a different proposal.
The -Wambiguous-types warning seems unnecessary to me. ...
@simonpj gets it. You seem to be of the brutalist school of software evolution.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I think you've misunderstood the motivation. It'd be informative to read through the thread I link to in July's cafe. The major point of this proposal is that GHC suggests switching on
I've answered that: the ambiguity is not desired. It's bogus, as a consequence of GHC's mis-leading message.
The cause I'm addressing is novice users who neither need nor understand ambiguous types. Their use case is not "meant to" anything. Their use case is because they're too trusting of GHC suggestions.
That would be a different proposal, that potentially breaks currently accepted code. By all means write it yourself. If the Committee judges it would be preferable to this proposal, I'll abandon this. The people putting
No this proposal (Point 7) is not disallowing ambiguity in type applications. To the contrary, it's allowing ambiguity without any rejection/extension set/nor pragma. So it's the opposite way round to your counter-proposal for expression signatures. |
It seems to me that the motivation is to aid both novice and expert users. If the only issue were that GHC makes a bad suggestion, the proposal could be as simple as "stop suggesting that users enable
You're quite right on that point, I mispoke. |
I was re-stating my motivation as wanting to avoid/minimise the scope of the ambiguity. I'm not claiming to understand why someone wants ambiguity. I manage to write all my code without it, and without type applications. So in the absence of someone chipping in here on use cases, I see three scenarios:
What worries me about 'named pragmas' -- where do I go to find out what that means exactly? Is that an existing feature or a pipe-dream? Is:
Those combined means it not necessarily easy to get from a field name to its definition to some pragma about the name. Addit: if by 'named pragmas' you mean something along the lines of
Then consider you might have [end of Addit] Then how do we persuade users to move from the module-wide Could I suggest the applicability of ambiguous expression signatures gets revisited as and when |
Yes, that's precisely what I meant, sorry for the confusion. Concretely, I would like to be able to write class Foo a where
foo :: a -> a
bar :: Int
{-# AMBIGUOUS bar #-}
These are all places where I guess my takeaway from this is that it would be nice to have a better understanding of where Haskellers desire ambiguous types. The only case I'm aware of is typeclass methods like That being said, I don't mean to stand in the way of this proposal. I think it would be a marked improvement over the status quo. I just saw a potential opportunity to improve it further. |
I'm happy to say I have no understanding of where Haskellers desire ambiguous types. I have no such desire. And I observe (most) novices don't either. So I'm trying to avoid the harm GHC is currently doing. (Most of your first para has gone over my head. I'm not trying to redesign the ambiguity in signatures. Wouldn't those considerations have been apparent to the originator?)
Good, because so far it's seemed you want to make the perfect the enemy of the vastly better. I'm not going to hang around for other proposals that claim to disambiguate pragmas; but seem to require code beakages; and seem to have gone nowhere for nearly 2 years; and anyway haven't anticipated a generalised way to attach pragmas to names. |
The underlying question @gridaphobe is asking is (I believe -- sorry if I'm putting the wrong words into your mouth): Is a type ambiguous, or is an identifier ambiguous? I think this is a good question. If a type is ambiguous, then the syntax proposed here is the right one. If an identifier is ambiguous, then a named pragma might be better. I'm in favor of calling a type ambiguous. The identifier can sometimes be a bit hard to pin down (examples: what do we do in an Given the long length of time this has been under consideration and the considerable silence-is-agreement among the committee, I'm going to make a deadline of Friday, at which point I will accept (and acknowledging @gridaphobe's statement that he wishes not to block acceptance). /remind me Friday to accept this |
@goldfirere set a reminder for Aug 9th 2019 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything is cleared up for me. Thanks.
👋 @goldfirere, accept this |
I hereby accept. @nomeata, I believe you do the next steps? |
Done, although you should/could notify the mailing list about the status change. |
This proposal's idea referenced in the proposed syntax for Modifiers, next-to-last bullet. I agree it makes sense to use a modifier rather than a pragma. Compare:
Only I'm a little worried over scoping: Modifiers are proposed to scope only over the immediately following lexical item they're prefixed to (minimal munch), whereas |
The proposal has been accepted; the following discussion is mostly of historic interest.
Per-signature pragma
{-# AMBIGUOUS #-}
to allow that signature's type to be ambiguous; instead of the module-wide-XAllowAmbiguousTypes
, which dangerously lifts ambiguity checking on all signatures.Also tweak the error reporting to avoid recklessly suggesting users turn on
-XAllowAmbiguousTypes
; and provide a flag-Wallowed-ambiguous-types
that shows the ambiguity message as a warning.Rendered