Haskell type synonym problem

This gives me the following error:

Out of scope: data constructor Blah

Why? I thought I could use a type synonym wherever I can usePerson

data Person = Person { weight :: Int, height :: Int }

type Blah = Person

person1 :: Blah
person1 = Blah 80 187 
+3
source share
2 answers

You have assigned a type to the Personname Blah, but the constructor for Personis still Person {weight :: Int, height :: Int}. Type constructors and type names are different and even stored in different namespaces in Haskell.

As an example:

> data MyBool = MyFalse | MyTrue deriving (Show, Eq)
> type Blah = MyBool

Here the constructors for MyBoolare MyFalseand MyTrue, each with a view *(no type parameters). Then I add an alias MyBoolto Blah:

> MyTrue :: MyBool
MyTrue
> MyTrue :: Blah
MyTrue

, , , , .

+6

GHC 7.8 :

{-# 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

, , Person - Person ia , .

+2

All Articles