News for hackers. Stuff that matters.
Re:Let the Type System do the Work by Dewie on Monday April 21, 2014 @01:38PM (#7622383)
> type Kilogram = Double

type synonym/alias.

Re:Let the Type System do the Work by jarrett on Monday April 21, 2014 @02:29PM (#7622715)
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.
Re:Let the Type System do the Work by jweese on Monday April 21, 2014 @03:12PM (#7623030)
That's why you want

    newtype Kilogram = Kilogram Double
which has no runtime overhead but does enforce the fact the Kilogram is a distinct type.
Re:Let the Type System do the Work by sparkie on Monday April 21, 2014 @05:48PM (#7624175)
We 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.
Re:Let the Type System do the Work by dllthomas on Tuesday April 22, 2014 @06:43AM (#7626835)
Though unfortunately can't handle (mass * accel :: Newton) without swapping out the Prelude.
Re:Let the Type System do the Work by antocv on Monday April 21, 2014 @03:45PM (#7623218)
Ada does it all.
Re:Let the Type System do the Work by Dewie on Monday April 21, 2014 @03:05PM (#7622975)
Yeah no kidding. I brought it up to show that you can have the same kind of thing that skybrian was talking about in Haskell.
Re:Let the Type System do the Work by skybrian on Monday April 21, 2014 @07:07PM (#7624582)
My point was that named types in Go are not type aliases like in other languages.