[Haskell-cafe] Read instance for GATD

corentin.dupont at ext.mpsa.com corentin.dupont at ext.mpsa.com
Fri Jun 25 05:04:30 EDT 2010


Hello Haskellers,

I'm having trouble writing a Read Instance for my GATD.
Arg this GATD!! It causes me more problems that it solves ;)
Especially with no automatic deriving, it adds a lot of burden to my code.

>data Obs a where
>    ProposedBy :: Obs Int       -- The player that proposed the tested
rule
>    Turn       :: Obs Turn      -- The current turn
>    Official   :: Obs Bool      -- whereas the tested rule is official
>    Equ        :: (Eq a, Show a, Typeable a) => Obs a -> Obs a -> Obs Bool
>    Plus       :: (Num a) => Obs a -> Obs a -> Obs a
>    Time       :: (Num a) => Obs a -> Obs a -> Obs a
>    Minus      :: (Num a) => Obs a -> Obs a -> Obs a
>    And        :: Obs Bool -> Obs Bool -> Obs Bool
>    Or         :: Obs Bool -> Obs Bool -> Obs Bool
>    Not        :: Obs Bool -> Obs Bool
>    Konst      :: a -> Obs a


> instance Read a => Read (Obs a) where
> readPrec = (prec 10 $ do
>        Ident "ProposedBy" <- lexP
>        return (ProposedBy))
>     +++
>      (prec 10 $ do
>        Ident "Official" <- lexP
>        return (Official))
>  (etc...)

Observable.lhs:120:8:
    Couldn't match expected type `Int' against inferred type `Bool'
      Expected type: ReadPrec (Obs Int)
      Inferred type: ReadPrec (Obs Bool)


Indeed "ProposedBy" does not have the same type that "Official".
Mmh how to make it all gently mix altogether?


Best,
Corentin




More information about the Haskell-Cafe mailing list