-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Guide: complex data types #15422
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
Guide: complex data types #15422
Conversation
|
||
As you can see, the type of a tuple looks just like the tuple, but with each | ||
position having a type name rather than the value. Careful readers will also | ||
note that tuples are hetergenius: we have an `int` and a `&str` in this tuple. |
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.
Spelling: hetergenius --> heterogeneous
Thanks! Go figure, I made sure there were no test errors, yet I commit spelling errors :( |
|
||
### Structs | ||
|
||
A struct is another form of a 'record type,' just like a tuple. There's a |
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 comma shouldn't be inside the quotes.
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.
Why not?
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 comma is part of the overall sentence, not the part in quotes.
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, but comma inside the quotes is proper English.
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.
Oh, you're right. I'm sorry. :)
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.
Technically speaking, it’s a matter of style, and putting the comma outside the quotes is the prevalent style in British English.[1] However, Rust documentation seems to generally follow American English (where putting the comma inside the quotes is more common), so putting the comma inside the quotes would be more consistent.
(Sometimes the British style is used in America, particularly in linguistic and philosophical works, because it is clearer and less ambiguous.[2])
I have fixed most of these issues. The 'newtype' thing remains. Do we have some consensus about what to do here? |
I think the word "newtype" is fine, it maps to a Haskell concept, but it should be explained as something other than a "synonym". |
Agree 'newtype' or 'newtype struct' is cromulent here. |
I somewhat disagree: the Haskell concept has the additional runtime representation changes over normal |
@huonw That's an implementation detail that AFAIK only matters to FFI, not really a semantic attribute of the construct. Rust also has the capability of unboxing newtypes during trans the same way it now unboxes nil-pointer-optimized types. |
That's not what I was talking about at all. In Rust, |
@huonw I don't see how the behavior of |
No, we're comparing the two ways to define wrapper structs. I.e. answering the question: if you need a wrapper type, how do you define it? In Haskell, you have a choice between We currently only call the This over-emphasis/preferential treatment of one-element tuple structs results in beginners writing code like this (this is just an example of our misteachings, not picking on the code/author), where the person has unfortunately made life harder for themselves by using a tuple struct with all the ugly (This last ugliness point could easily be addressed by allowing some form of field accesses on tuple structs, but we don't have that now, and the preferential treatment of |
I think you're still focusing too much on the distinction between Strictly speaking, Haskell's I think it's perfectly reasonable to call I do agree that our current tutorial does suggest that |
This doesn't really make sense... of course In Rust, both
I don't understand the relevance of this. The first sentence is exactly what I have been saying, and then you're trying to justify why Haskell has
But "nobody" thinks of using a single-field struct, because we use special terminology for the single field tuple version, and ignore the normal version.
I wasn't saying they are useless, just that we're emphasising them too much by using a fancy name from another language where it has important meaning that is irrelevant to Rust. |
…=brson I'm not happy about the hand-waving around `cmp`, but I'm not sure how to get around it.
internal: Record import source IDs cc rust-lang/rust-analyzer#14079
I'm not happy about the hand-waving around
cmp
, but I'm not sure how to get around it.