3 ms·
It depends on the implementation. I'm not familiar with Scala, but in Haskell, using `newtype`s to achieve this creates absolutely no extra runtime overhead, on
by radicality 13y ago
It depends on the implementation. I'm not familiar with Scala, but in Haskell, using `newtype`s to achieve this creates absolutely no extra runtime overhead, only compile-time overhead when the types are checked.
- axman6 13y agoThis isn't completely true, there are issues which come up with code like newtype Foo = Foo Int map (\(Foo x) -> x) listOfFoos which should be a no-op at runtime because the representation of Foo x and x are the same, but due to the newtype, the traversal does need to occur. [1] discusses a way to avoid these problems. Basically these newtype should only ever be needed during type checking, and should really be erased after that; once you've type checked everything, then you know your program won't ever treat something which is a non Foo Int as an Int, so you can then get rid of the compile time tag and gain better optimisations. [1] http://research.microsoft.com/en-us/um/people/simonpj/papers/ext-f/coercible.pdf http://research.microsoft.com/en-us/um/people/simonpj/papers...