Re:Thoughts on Rust, a few thousand lines in
by afraca on Thursday January 10, 2019 @03:49AM
(#18872468)
This is common in Haskell as well using `newtype`. You can
have type aliases like
type A = B
but you can use the following function with a B: f :: A -> _
whereas newtype EscapedString = EscapedString String
f' :: EscapedString -> _
would prevent from using f' with the wrong data. Newtype is a zero-cost abstraction.
Your type structure at no extra runtime cost is String : ParsedString : EscapedString.
This ensures you don't escape strings before parsing them too. Nice!