Conversation
|
I was thinking about the prime thing the other day actually. I'd be in favor of just getting rid of primes altogether actually. JS doesn't allow them, and now we have the new operator rules, there's not much reason for not using JS identifiers IMO (perhaps reserving |
|
This looks great to me. Let's just chat a bit about the prime thing before merging, since now would be the time to break it. |
|
Well, I'd argue very strongly against that personally. I understand the "better javascript" angle, but I'd also like PS to be a language that I actually like, and I much prefer priming to numbering variables - you can use them as semantically different things, Also there are still lots of other things we'd have to deal with, given all the reserved and built-in names. I forgot to mention, this prime-renaming rule only applies to local variables. If you name something |
|
What about |
|
Actually, come to think of it, why not just rename ticks to underscores? It's deterministic, and unlikely to clash. And on the off chance it does, we can give the user a nice error message. |
|
Or for that matter, what about |
|
I was trying to improve the readability of the JS as well, which is why eliminated the underscores (and numbers where possible) from dictionary names. Both |
|
I definitely see a lot of value in numbering identifiers and I agree underscores and dollars look bad in generated code. I'd just like to see How would you name the equivalent of |
src/Language/PureScript/Renamer.hs
Outdated
There was a problem hiding this comment.
Any particular reason for using v?
Didn't you want to try the lettering scheme instead here? a, b, c, ..., aa, ab, ... etc.?
I'm not too bothered either way, this is obviously a big improvement.
There was a problem hiding this comment.
I would prefer that, yeah, I couldn't figure out an elegant way to generate identifers like that though. If you have one I'll definitely use that instead!
There was a problem hiding this comment.
Something like
toIdent :: Int -> ShowS
toIdent = showIntAtBase 26 (chr . (ord 'a' +))perhaps?
It's not quite right, but not terribly far off.
|
I would probably be updating a |
|
Damn, tests failed as I removed some constraints. I thought |
|
Yeah, I ran into that issue the other day too. I'm not sure, I think it might be a |
|
If we just use JS identifiers, we could use a unicode prime instead. |
|
Sorry, this one works. |
|
Any thoughts on unicode? |
|
I'm slightly hesitant, as I have low expectations of what JS engines will accept, but I'd suggest we rewrite |
1dc5c7f to
4b26130
Compare
I'd be in favor of that too. I think that primes are too hard to notice compared to numbers or underscores. And they quickly get out of control if you have more than one. |
|
👍 on removing primes from me as well; even in Haskell code nowadays I use |
4b26130 to
4236b78
Compare
|
So this is obviously a bit of a point of contention, but the only reason I want to figure out what we're doing with it, is that we're at a good point in time to break things. I think if we can aim to use JS identifiers in 0.9 (no mangling at all), that would be a good thing. And if we break this in 0.8 now, we only have to finish off operator aliases to make that be the case. |
|
Not mangling is something we don't have the option of doing, unless we want to be subject to the arbitrary banning of various other words due to existing keywords and globally available values in JS. I really don't want that. |
|
I must have prime. But I'm fine with unicode prime. Would be cool if ordinary prime were rewritten to unicode prime to escape it. |
So what I'm proposing is:
I'm fine with making an exception for the |
|
Okidoke, I'm totally cool with that - I think the only thing we need to make that happen is start requiring aliases, so they can disappear entirely during codegen? (and a decision on primes) |
|
Yes I think so. So here are some options for primes:
Any others? |
|
Oh wait! I assume this keeps the current starts-with-lowercase-or-underscore rule for PS identifiers too? |
|
Ah right, yes. |
|
The ES5 unicode primes solution would be my preference - we've been talking about ES5ifying some of our other codegen too, like for traversing the keys of records when copying, etc. |
|
Let's discuss "get rid completely" though. Given that converting primes to unicode primes can only be described as a hack, then if the issue is the difficulty of typing a unicode prime, isn't the solution really to set up the editor in such a way as to make the conversion automatic? It would seem that unicode operators will make editor support necessary eventually anyway. |
|
So I'm guessing we won't ever be allowing unicode primes in PS identifiers then to avoid the collision? |
|
@michaelficarra I'm interpreting this as "they'll be equivalent". |
|
Yeah, that's the way I'd see it too - |
|
I mean, any editor worth it's salt should be able to bind |
|
You could say the same about removing |
|
Speaking of which, it'd be nice if that worked 😄 |
|
Well yes, but there's not really a good reason for that IMO. Closer compatibility with JS identifiers and cleaner codegen is pretty worthwhile I think. Edit: I mean, I see the value of unicode syntax, but it can be implemented with sufficiently nice tooling since it exists only before compilation. |
I don't like that idea at all. A few reasons:
|
|
Prime as a symbol seems common enough that that automatic conversion seems worthwhile to me. My only other argument is things kinda freak out when you use it at the moment when messages are printed: |
|
@tfausak no, |
|
I'm really on the fence. I don't use primes much, but I see their appeal. On the other hand, anything to do with automatic replacement of characters seems unpleasant. |
|
There are more primed identifiers used in the compiler than there were lines in the initial commit now... I'm sure they can't all be me 😄 |
|
Ok 😄 I'll say this - I don't use them at the top level much, and for intermediate variables, there are better choices when compiling to JS IMO. Given we warn on all shadowed names, there needs to be some way of saying "like variable X, but not variable X" in |
|
Well, there's always a |
|
Oh, that's what |
|
Haha, oh dear 😄 That's probably only obvious if you compare the types in Haskell lens and PureScript lens. In fact, maybe nobody else at all gets it other than Hardy and I, as I think I've probably had to explain the P to anyone I've ever talked to about it. I guess my concern with the unicode approach is: it will almost certainly be used at the top level at some point, and when it happens it will confuse people that trying to call or Also if we sort this rule out it would be really nice to enable its use in types too to avoid the |
|
The fact there are many things it can be mistaken for is part of the problem too: that's a can of worms unicode opens for almost any character, but given that it's a common symbol it would perhaps be unexpected that when it appears in code it's not the most easy-to-hand variant of it. |
|
I vote 👎 on unicode prime because I think its confusing and is barely distinguishable from a lot of other quote-like characters. I think the current approach is fine. |
|
So unicode prime is already possible, since any unicode letter is fine. I'd just like to decide what to do with regular primes, since they currently get codegen'd as |
|
There shouldn't be any issue with adding primes to the letters allowed in type names, I think, since they don't exist in generated code. Data constructor and class names are different, of course. |
|
In any case, I think we should merge this, and open a "Discussion" issue to discuss options while we're testing the 0.8 release candidate. |
|
Ok, cool |
Resolves #1697
I also took the opportunity to tweak two other aspects of codegen:
x$primeforx'it will now generate a name likex1(orx2ifx1is in scope, orx3ifx1andx2are in scope, etc.)__dict_Functor_0it will generatedictFunctornow, and then start numbering if there are multiple in scopeI understand if you object to the
x'change, as it's slightly rewriting the input, but I think it's not a very difficult rule to understand, and generates much nicer names IMO.