The difference between T
and struct Wrapper(T);
in Rust is far less pronounced than the difference between T
and data Wrapper = Wrapper T
in Haskell. A data
type in Haskell has a runtime representation and adds a separate layer of laziness. And while rust doesn't make many guarantees about data layout, I don't think you have much to worry about in terms of overhead. Probably the worst thing I know of is that a repr(C)
struct might not be ABI compatible with the wrapped type, but there's an accepted RFC to add a workaround for that.
The bigger issue IMO is deriving trait impls and inherent methods for these types. Neither Rust nor Haskell has this easy. Rust at least has a reasonably efficient macro system to help with this (Template Haskell eats children for breakfast), but then it suffers from a lack of higher ranked types and requiring difficult design choices around ownership. (Hmm, should I take by value, or maybe require Clone? Ah, I think borrows will be good... wait a second wtf why is there no AddAssign<&'a i32>
for i32
adfgdaghsfgssfg)