[Haskell-cafe] nooby question on typing

Gökhan San gsan at stillpsycho.net
Sat Sep 13 13:45:46 EDT 2008


On Saturday September 13 2008, Han Joosten wrote:
> >  data Rule = RuRule
> >            | SgRule
> >            | GcRule
> >            | FrRule
> >                deriving (Eq,Show)

Here, Rule is a type constructor, whereas RuRule and others are data 
constructors. Just like:

> data Bool = False | True

The type of RuRule is Rule and is not related to the RuRule type you are 
defining afterwards. What you want to do is probably this:

>  type Rules = [Rule]
>  data Rule = Ru RuRule
>            | Sg SgRule
>            | Gc GcRule
>            | Fr FrRule
>              deriving (Eq,Show)

>  data RuRule
>     = RuRule { rrsrt :: Char
>              , rrant :: Expression
>              , rrfps :: FilePos
>              } deriving (Eq,Show)

>  data SgRule
>     = SgRule { srfps :: FilePos
>              , srsig :: Rule
>              , srxpl :: String
>              , srtyp :: (Concept,Concept)
>              } deriving (Eq,Show)

...

You can now form a Rules list and use pattern matching on its members.

-- Gokhan


More information about the Haskell-Cafe mailing list