- 3comments
- 5comments
- 14comments
- 401comments
- 319comments
- 9comments
- 75comments
- 128comments
- 19comments
- 247comments
- 34comments
- 93comments
- 92comments
- 5comments
- 2comments
- 750comments
- 35comments
- 26comments
- 109comments
- —discuss
- 130comments
- 230comments
- 234comments
- 44comments
- 46comments
- 301comments
- 50comments
- 72comments
- 11comments
- 18comments
Good article on Rust's strengths with types. If you like this, you may be curious how you might build your own parse capabilities. I like the Rust crates Winnow and Nom, and also the Rust traits From and Into.
Nonempty type wrappers are a stark reminder that we are missing out on refinement types.
I was thinking about its implementation, too, and ended up deciding that it was probably a performance optimization.
`Vec<T>` stores all data on the heap, so getting anything out of it involves a pointer deref and possibly also an array bounds check. This `NonEmpty<T>` type keeps the first element of the list in a location that supports some low-level optimization that might make a significant difference when accessing the first element is much more common than accessing subsequent elements.
Rust has a proposal for this, in the form of pattern types. It's on nightly, but quite far from being ready for prime time.
This is great. Alexis King actually stated that, had she known how popular “Parse, Don’t Validate” had been, she would have written it in a language more widely used than Haskell.