3 ms·
In Haskell? I wouldn't do that. That improves readability, but it doesn't allow the compiler to enforce correct unit usage. If a Kilogram is just a synonym for
by jarrett 12y ago
In Haskell? I wouldn't do that. That improves readability, but it doesn't allow the compiler to enforce correct unit usage. If a Kilogram is just a synonym for a Double, you can pass it in where other meanings of Double are expected. E.g. you can pass Kilograms into a function that takes Pounds. Which you don't want to do.
- Dewie 12y agoYeah no kidding. I brought it up to show that you can have the same kind of thing that skybrian was talking about in Haskell.
- jweese 12y agoThat's why you want newtype Kilogram = Kilogram Double which has no runtime overhead but does enforce the fact the Kilogram is a distinct type.
- sparkie 12y agoWe probably wanna add to it to make it useful {-# LANGUAGE GeneralizedNewtypeDeriving #-} newtype Kilogram = Kilogram Double deriving (Show, Eq, Ord, Num, Real, Fractional, Floating, ...) And remind ourselves that Haskell is really quite expressive.
- dllthomas 12y agoThough unfortunately can't handle (mass * accel :: Newton) without swapping out the Prelude.
- antocv 12y agoAda does it all.