-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Switch <>
back to []
#148
Switch <>
back to []
#148
Conversation
// Possible syntax for HKTs. | ||
pub trait Monad[M[T]] { | ||
// ... | ||
} |
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.
How does this bring the ability to have nicer syntax for HKTs? Wouldn't the example be exactly the same when written like this?
pub trait Monad<M<T>> {
// ...
}
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.
That is one syntax proposal for HKTs (following in Scala's footsteps) which is ok (There are better alternatives that focus more on inference). I find []
a lot more composable than <>
(i.e., you can nest them without it being cryptic to read).
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.
I don’t see this as a separate point from the second point.
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.
Define "cryptic to read". The nesting properties of []
and <>
are identical. You personally may simply have more experience reading nested []
due to being used to Scala. Me, not being a Scala programmer, very rarely encounter nested []
and I find there to be no benefit at all over <>
.
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.
Yes, imo, []
is much nicer to read than <>
without being exposed too much myself (to the []
syntax).
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.
I think that this claim should be removed—it has no substance apart from the previous claim, is subjective and is not dealing with a concrete situation (HKT is far future).
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.
Agreed, fixed!
|
||
4. There's precendence for it. Scala's syntax for generics is awesome. It imposes very little effort (I think) when reading and understanding. | ||
|
||
6. Because it's consistent and has no ambiguities, one can finally use motions like `%` in Vim (and alternatives in other editors.). |
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.
I have never had an issue using %
in Vim. We do not support the use of <
or >
as an operator inside of a generic type parameter list, which means there is no problem finding the matching <
or >
when using %
.
One of the key benefits of using I am surprised by how much easier I find
Using |
I don't buy the matching argument. I will readily admit that it's true that That said, I appear to have broken something, because I swear it used to work for me out of the box, but right now |
Big 👎 here. |
} | ||
``` | ||
|
||
4. There's precendence for it. Scala's syntax for generics is awesome. It imposes very little effort (I think) when reading and understanding. |
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.
After the first sentence, this is pure subjectiveness and not distinct from the earlier points.
What is of note here is this. At the time when Rust changed from []
to <>
, there was no known precedent in a C-style language for []
-generics: C++ and Java, for example, used <>
. Since then, []
has been adopted in at least one fairly popular language, Scala.
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.
Will fix.
I think the original issue (from what I heard, don't quote me) to switch was because |
|
||
Recently there has been a lot of talks on simplifying the syntax. Starting from removing the sigils `@` and `~` and making lifetimes less syntax heavy (through various proposals). I think changing the current generic syntax to `[]` will make it that much better and clearer (I think `[]` is much easier to read). | ||
|
||
1. `[]` is easier to type than `<>`. |
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.
I disagree. It actually takes less hand movement for me to type <T>
on my US English keyboard than for me to type [T]
.
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.
<>
needs a shift operator (at least for me), while []
doesn't.
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.
@thehydroimpulse You should specify on most keyboards; you simply can’t make such assertions without appropriate guard conditions.
@kballard On the standard US English keyboard, []
don’t require the Shift
modifier to enter them whereas <>
do. The impact of this is reduced for [
as it will normally be followed by an uppercase letter, incidentally, but it won’t for ['a
and it won’t for ]
unless the last character was also uppercase. This, I presume, is what you are referring to here: for <T>
you can just hold the Shift key for all three characters, whereas with [T]
you can’t. I accept this case. Still, in most cases I find []
a little easier to type than <>
.
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.
@chris-morgan Fixed. Thanks!
To parse this, when we see a
Could be either indexing or taking the value of a generic function, substituting a type parameter, but you won't know. |
@cmr Yes there's some ambiguities around arrays with this proposal. |
|
||
1. `[]` is easier to type than `<>` on *most* keyboards. | ||
|
||
2. `[]` delimeters are always matching. |
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.
This needs to be clarified, with reference to the comparison operators <
et al. It should be merged in with the sixth point, the practical benefit of this.
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.
Fixed!
|
||
This is a very easy change to make. | ||
|
||
## Downsides |
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.
s/##/#/
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.
Fixed!
|
||
# Detailed design | ||
|
||
This is a very easy change to make. |
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.
That’s… not much of a detailed design. How about saying something like “in type parameter lists, replace <
with [
and >
with ]
.” and giving examples of T<U, …>
and f::<T, …>()
?
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.
Fixed.
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.
The
@cmr: |
We can't use |
@kballard () for indexing interests me quite a bit. Can you please elaborate your reasoning why Rust can not apply it? Can you tell an example where there is a need to be able to both call and index a value? |
As far as the ugliness of the current type application syntax is concerned, how do people feel about, instead of,
writing
? I don't believe It's not shorter, but it's more readable and perhaps less ugly. |
@glaebhoerl I don't like |
@glaebhoerl how would that scale for more complex declarations? Do you put type in front of each parameter? What about nesting? Also rust might end up adding stuff like constant integer parameters and things like that, "type" wouldn't fit those semantically. What would you do with lifetime parameters? I guess you could say there're a type but that's stretching it a bit IMO. I don't think this solves anything really, I don't like the |
|
I never implied that it's perfect, only that it might suck less. @simias I was thinking the rule would be that if providing a kind annotation ( |
|
@adrientetar that's more of a rationalization really. I mean, you can think about it that way but to me But anyway, this is off topic since this proposal still requires |
@almale RFC 34 defines traits that can be used for implementing the indexing operator on arbitrary types (we actually already have an existing trait for this, but it's badly-designed and nobody uses it). RFC PR #114 provides unboxed closures by adding traits to represent function calling. This allows arbitrary types to be callable (as Implementing both traits on the same type allows a value of that type to be both indexable and callable. This requires that the indexing and calling operators be syntactically distinct, which means |
@almale I don't know what a real-life example of such a type will be, but the fact remains that our traits allow for it, and therefore Furthermore, you cannot resolve that by getting rid of indexing in favor of using calling as the indexing operator, because that doesn't support the distinction between immutable and mutable indexing, or the ability to assign to an index. Note that while the callable traits have variants for mutable and immutable, one type is not allowed to implement both (or more accurately, |
C uses [] for index arrary. I don't think there is enough reasons to change
|
Hi, could you explain the use case for this? I can't see it. While scala Stefan
|
Interestingly, RFC #34 and RFC PR #114 are quite similar to how Scala approaches these problems. One difference is that Scala doesn't require using any particular trait; a type just defines methods of the appropriate name if it wants to use I would think, as @boggle suggests, it's up to you whether you want to have objects that are callable and indexable with a different meaning for each one. If that's more of an accident than an actual goal, then couldn't you just use the same set of names for both cases? In rvalue position, expand to ( Not to say that it's right because Scala does it, or even that it's right at all for Rust. The two languages run into similar challenges due to both trying to bring functional programming to mainstream ecosystems, so I thought I'd share. |
In merit to this issue see this: http://www.reddit.com/r/rust/comments/2bbeqe/it_started_out_with_great_enthusiasm_but_ended_up/ We had a small conversation here about one statement from the author: http://www.reddit.com/r/rust/comments/2bbeqe/it_started_out_with_great_enthusiasm_but_ended_up/cj3v5x6 Anyway, I'm one of them that wish we could switch back to I don't see that much the point that of
|
I really think readability should beat familiarity. Your example is a good one, as it's very jarring to mentally parse, because There are angled brackets in Unicode, but (understandably) we don't want to The characters <> really only serve as operators, not fake brackets. |
I must admit to being more sympathetic now to the "it looks nicer" argument for |
@kballard regarding that, I'll quote JouMaSePLoS:
Also, as others pointed out, scala use However, keep in mind that a language syntax last 20+ years, so I really hope we couldn't carry for 40 years the operator |
That's quite a good point. Though I don't agree with the implication of the latter half of the comment that |
I was very confused when I first saw Scala code using Once again, I think Parentheses are in fact the most intuitively correct option, as generic types, or types parameterized over types, in a very precise sense are like functions, or values parameterized over values. (Or not even "like": they are functions at the type level. More specifically, they're the same thing on the type level as enum variants are on the value level. General type functions, or associated types, are the precise analogy for general value-level functions, of which "normal" generic types are a specific case in the same way that enum variant construction is of function calls.) It's not by accident that Haskell shares the same syntax for function calls, data construction (enum variants), and type construction (generics). (As a side note: I think we could then use |
@glaebhoerl We can't use |
In a language that had made different fundamental choices about inference and overloading, It's not considered a bad thing in any language that supports operator overloading that it's possible to overload both 'function call' and 'index' operators depending on what your intention is. And even though maps are functions, templates are still more like maps than they are like other functions. |
"Can't" is a strong word. D does it. (They use I think it's much less bizarre than the clash of |
IMHO both |
@DAddYE Forgot to reply. I think a member of the core team should way in before this is reopened. I don't want to continue a needless bike shed for the sake of it with a low-chance it's going to be taken seriously. |
Update and rename 0000-isHtmlSafe.md to 0139-isHtmlSafe.md
Here we go.
Thoughts?