4 ms·
Unboxed tagged types to the rescue: http://etorreborre.blogspot.co.uk/2011/11/practical-uses-for-unboxed-tagged-types.html http://etorreborre.blogspot.co.uk/20
by noelwelsh 13y ago
Unboxed tagged types to the rescue:
http://etorreborre.blogspot.co.uk/2011/11/practical-uses-for-unboxed-tagged-types.html http://etorreborre.blogspot.co.uk/2011/11/practical-uses-for...
Scalaz implements this, so you can use it straight away. We use it mostly to control implicit selection.
- kasey_junk 13y agoTagged types also have their problems. 1st they don't propagate, call a function on the tagged type and it returns the underlying type. 2nd they aren't type safe against the tagged type, so you can pass tagged types into functions that take the underlying type by default. 3rd in practice my code with tagged types ends up having lots of boilerplate and/or magic code that is hard to understand. 4th there are some pretty heinous compiler bugs that you will encounter with tagged types.
- noelwelsh 13y agoIt seems you've done a lot more with them than I have. I'm looking forward to crashing the compiler -- the true badge of honour amongst Scala developers ;-)
- yummyfajitas 13y agoThey absolutely shouldn't propagate. val x = 1.0 @@ Kilograms val y = x*x y is not a Double @@ Kilograms.
- kasey_junk 13y agoIn many cases I'd like it to be.
- laureny 13y agoValue classes make tagged types obsolete: http://docs.scala-lang.org/overviews/core/value-classes.html http://docs.scala-lang.org/overviews/core/value-classes.html
- noelwelsh 13y agoThey still have uses for disambiguating implicits. There are at least four monoids for the Int: 0/+, 1/*, MinValue/Max, and MaxValue/Min. It is useful to tag them so one can specify which monoid one wants.