Repository navigation
Require namespacing fixity declarations for type names - #65
Conversation
|
IMO looks better than We are declaring fixity, so it makes more sense to place 'infixr' at the beginning, not 'type'. |
|
You raise a good point. I can understand wanting to put If no one objects, I'll repaint the proposal with this new bikeshed color. |
|
I'm in favor of this proposal, without caring much about the concrete syntax. |
|
I've updated the proposal to use the new |
|
How will this interact with DependentHaskell? If an operator appears in a
type, which fixity will it get?
…On Jul 30, 2017 5:44 PM, "Richard Eisenberg" ***@***.***> wrote:
I'm in favor of this proposal, without caring much about the concrete
syntax.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#65 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABzi_dBhlcO82164cqlbkYr2zjfWLtsaks5sTPklgaJpZM4OnaEC>
.
|
|
This sounds like a @goldfirere question, but I'll try to answer nonetheless. I think what this question is getting at is that there are of some named constructs which can be used in multiple namespaces. Well, I say "some", but at the moment there's really only one such thing: data constructors, via I put a sentence in this proposal about how promoted data constructors can't be assigned a fixity with (Correct me if I'm totally off-base here, @goldfirere.) I didn't think to include this in the proposal, since Dependent Haskell is its own, somewhat orthogonal thing. But I can fold in this discussion in the section about promoted data constructors if you'd wish. |
|
I just had a thought. In the proposal, I give an outline for phasing about infixr 5 $
($) :: (a -> b) -> a -> b
f $ x = f x
type f $ x = f xNow it's true that as a consequence of the way GHC currently works, the I imagine the programmer would be quite annoyed by this because the fixity of type-level To avoid these kind of headaches, we should probably scale back the scope of these warnings to only include scenarios where a fixity declaration refers to something that is only a type-level name, like this: infixr 5 $
type f $ x = f xThis will eventually fail to compile, so it makes sense to warn here. However, I don't think we'd be able to warn about every such scenario which will break in the future. For instance, what about this? module A where
infixr 5 $
($) :: (a -> b) -> a -> b
f $ x = f x
type f $ x = f xmodule B where
import A
type Foo = Maybe $ Maybe $ IntThe code in My hope is that such a scenario happens rarely in practice—but maybe I'd need to try building all of Stackage against a version of GHC that takes away |
|
@treeowl Good question. I find that it's easiest just to think about the fact that Haskell has several different namespaces. Every name belongs to precisely one of these. A fixity is a property of a given name. This fixity exists independent of what context a name is used in. So, if our old friend And I disagree with some of @RyanGlScott's response to @treeowl's question. I hate to nitpick like this, but this is all quite subtle: you state "some named constructs which can be used in multiple namespaces". But a namespace is something that's a property of a name (in my parlance, at least). I think you mean multiple contexts, here. As explained in my parenthetical above, GHC does its lookup differently in different contexts. And it's true that there's only one sort of name which makes sense both in a data-level context and a type-level context: data constructors. And so I was pleased when I read in your proposal that the fixity of a data constructor used in a type-level context is the same as its fixity in a data-level context. (For now, it's technically possible to have different fixities in the different contexts. But that would be awfully confusing.) Bottom line: you assign a name (in whatever namespace it lives) a fixity. And then that name has that fixity in whatever context it is used. |
|
In response to @RyanGlScott's most recent worry: you could always use I do believe that your release schedule doesn't fully follow the 3-release policy. Let GHC0 be the release that this is implemented in. Then, GHC-1, GHC0, and GHC1 won't all be able to compile the same code without warnings, if the warning is in |
|
The namespace question is brought into focus by Here we have a type constructor and a data constructor called The question in my mind is: should it be possible to give the two
I don't feel very strongly. But I think there is a reasonable case for the status quo; and if it is currently buggy I'm sure it could be made to work properly with no more effort than implementing something new. |
|
@simonpj's Now, it seems more compelling to allow the two |
|
The idea of adding a namespace keywords for value-level things is intriguing. I'm personally not a fan of the keyword Moreover, this presents an opportunity for a GHC warning that we could emit even after the three-release windows passes. If you have code like this: module A where
infixr 5 $
($) :: (a -> b) -> a -> b
f $ x = f x
type f $ x = f xThen GHC could warn: As you noted, this would catch this code in the act before the breaking change drops. I'll update the proposal soon with the above changes, as well as fixing the three-release-policy window and including a more detailed discussion on things used in multiple contexts in light of @treeowl's and @simonpj's comments. |
|
I've updated the proposal to include the |
|
Four weeks have passed since this proposal was first submitted, and I believe the proposal in its current form resolves folks' concerns. Given the lack of continued discussion, I'd like to submit this to the committee for consideration. cc @nomeata |
|
I’ll shephard this one. |
|
I had not realised this, but today it is already possible to have one fixity for a type-level T and another for a value-level T: In module |
|
The only consistent positions seem to me to be A. A fixity is a property of an entity, where "entity" is something like "the type constructor T" or "the data constructor T". B. A fixity is a property of a lexeme like "T", irrespective of namespace. That leads to different change to GHC which would mean looking up fixities by string rather than by Name. Then in the Foo example pointed to by the above link, we'd presumably have an ambiguous fixity for T. BUT that would run into trouble when you said "a I think B is a non-starter, for the reasons mentioned above. So, at the AST level I think we must have (some version of) Ryan’s proposal. The only question is whether or not we expose that expressiveness to the programmer. That is, we should fix the TH problem by fixing the AST, so that we can round-trip through TH without losing information. But at the source-code level we are not forced to make a change. It is tiresome that, to get a different fixity for the type-level and term-level things, you have to declare them in different modules. If they are part of the same data type, or same mutually-recursive group, that might be awkward or impossible. It's a wart. But it's not a very pressing wart, and arguably we have bigger fish to fry. |
|
How would it work to round-trip via TH? Suppose I have What would I guess the question is what fix for the AST do you have in mind? Right now, the fixity declaration is duplicated in the AST, with one declaration for each name. Are you proposing not to do this... say by storing a string instead of a name in a fixity's declaration AST node? (That would actually seem to work, given that you can't, I believe, declare the fixity for an entity declared in a different module.) |
|
I have not worked out exactly what the AST should say. Presumably it must record enough to reconstruct what was originally written. Currently a |
|
But you'd only be able to tell the difference after the renamer... so I think that definition isn't quite right, but I do see how such a thing could round-trip through TH. |
|
Well, if Ryan's proposal can work at all, it must have an AST. Just use that AST. My bigger point is only that AST can be more expressive than the concrete syntax of the source language. |
|
Perhaps I'm missing something obvious, but I don't see how this would roundtrip through TH without changing the concrete syntax. Can you give an example illustrating how this would work? (Also, apologies for jumping the gun on submitting this for committee approval—it looks like there's still some discussion to be had. Feel free to remove this from committee consideration if you deem it appropriate to do so.) |
|
If it is not user facing, there is no need for a proposal IMHO. |
|
That's what I figured, thanks. Nevertheless, I don't want to close the issue quite yet—the exact design is still somewhat murky, and it's possible that in attempting to implement this, I might discover a hidden roadblock. |
|
Sure, please have a look what's possible and what's not and let us know when you have made a decision. Thanks! |
|
While I imagine a fix for the current TH bug is possible without user-facing consequences (beyond clients of TH, who are used to breaking changes), I don't think this proposal needs to be intimately tied to that bug. In other words, even with the bug fixed, I think this proposal has merit. |
|
While attempting a prototype implementation of the plan in #65 (comment), I realized something that I hadn't considered before. I had heretofore assumed that fixity declarations were unique in their ability to refer to both value- and type-level entities simultaneously, but it turns out there is another sort of declaration with this power: {-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Foo where
{-# DEPRECATED (!@#$) "Don't use this." #-}
(!@#$) :: Int -> Int -> Int
x !@#$ y = x + y
type family x !@#$ y{-# LANGUAGE TypeOperators #-}
module Bar where
import Foo
bar :: Int !@#$ Int -> Int
bar _ = 1 !@#$ 2When compiling Unlike fixity declarations, |
|
Good observation! This indeed strengthens the proposal. (And in my opinion supports the point that |
|
Yes -- very interesting. No one will be surprised when I say that we should have |
|
Well, you say "such pragmas", but I literally cannot think of another example of a pragma besides
So as it stands, there's just two things that happen to have this weird interaction with namespaces. I'll admit that I don't feel motivated to overhaul this much of the language just to fix one pesky bug, so as things stand, once I have an implementation of @simonpj's ideas from #65 (comment) that adequately fix the Trac ticket, I'll close this proposal. |
|
Depending how you count:
|
Yes I was thinking about import and export lists too, where this comes up. E.g. can you export a pattern synonym P thus? I think not. We've often speculated about being able to write or some other prefix, to disambiguate. So although I hate to destabilise a nearly-done proposal, how hard would it be to generalise it somewhat? |
|
I'm all for And you can annotate types, even with much the same syntax we're considering generalizing: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/extending_ghc.html#annotating-types |
|
@RyanGlScott We have consensus in the committee to accept this, by extending Would you care to amend the proposal accordingly before I merge it? |
|
To be clear, what exactly should be amended? The discussion currently revolves around just infix declarations, so should the entire prose be updated to integrate I think there's one other thing I'd like to change about this proposal. Back when I originally submitted this, I was under the impression that this was the only way we could fix Trac #14032, so I reluctantly volunteered myself to implement. But given that there's a middle ground in #65 (comment) that doesn't require any changes to the source language to implement, I'm going to implement just that, and resign as the implementor of this future (more-far-reaching) change. Is that acceptable? |
|
I don't think we accept/reject implementation responsibilities. So, I suppose that means it's acceptable, yes. This actually strikes me as a great beginner project to implement. |
Can they be treated just the same? Also when it comes to warnings about ambiguity etc.? I am hoping that you’ll do the thinking for me :-)
Yes, it totally is (although I hope you are still interested in leaving the proposal in a good state, including the |
|
@nomeata, I've updated the proposal to give lip service to |
|
LGTM |
This implements workaround (2) in #326 (comment), which has the advantages of: (a) Not needing to generate a bunch of superfluous code. (b) In the event that ghc-proposals/ghc-proposals#65 is implemented, it will be much easier to notice that the hack can be removed (since the workaround will then produce an error).
The proposal has been accepted; the following discussion is mostly of historic interest.
This proposes a way to clean up GHC's implementation of fixity declarations for names that live at both the value and type level, as the current implementation is rather unsatisfying (and sometimes broken).
Rendered