This gives me the following error
Not in scope: data constructor
Blah
Why? I thought that I can use the type synonym everywhere I can use Person
data Person = Person { weight :: Int, height :: Int }
type Blah = Person
person1 :: Blah
person1 = Blah 80 187
You've aliased the type Person to the name Blah, but the constructor for Person is still Person {weight :: Int, height :: Int}. Type constructors and Type names are different and are even kept in different namespaces in Haskell.
As an example:
> data MyBool = MyFalse | MyTrue deriving (Show, Eq)
> type Blah = MyBool
Here the constructors for MyBool are MyFalse and MyTrue, each with kind * (no type parameters). I then alias MyBool to Blah:
> MyTrue :: MyBool
MyTrue
> MyTrue :: Blah
MyTrue
This should help enforce the idea that while a type's constructor might share the same name as the type itself, they are not the same things.
In the hottest GHC 7.8 you could write in such manner:
{-# LANGUAGE PatternSynonyms #-}
data Person = Person { weight :: Int, height :: Int }
type Bar = Person -- type synonym
pattern Baz = Person -- constructor synonym
person1 :: Bar
person1 = Baz 80 187
But sure, don't forget Person is a type and Person ia a constructor and both are in different scope.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With