Re:Hack: a new programming language for HHVM
by munificent on Thursday March 20, 2014 @04:30PM
(#7438484)
> It is merely a type alias, like e.g. Haskell's and ML's "type", or isn't it?
It is, but it freely allows conversion between the aliased types.
typedef int Feet;
typedef int Meters;
int main() {
Feet height = 6;
Meters inEngland = height; // <-- OK. :(
}
Re:Hack: a new programming language for HHVM
by anaphor on Thursday March 20, 2014 @04:42PM
(#7438598)
I'm pretty sure you and the parent were thinking of Haskell's `newtype` not `type`
λ> :{
Prelude| type Feet = Int
Prelude| type Metres = Int
Prelude| :}
λ> let a = 5 :: Feet
λ> let b = 4 :: Metres
λ> :t a
a :: Feet
λ> :t b
b :: Metres
λ> a + b
9
λ> let f = id :: Feet -> Feet
λ> f b
4
And may I ask why you say "typedef" is unsafe? It is merely a type alias, like e.g. Haskell's and ML's "type", or isn't it?