[Haskell-cafe] Read instance for GATD
Edward Kmett
ekmett at gmail.com
Fri Jun 25 14:03:05 EDT 2010
It turns out that defining Read is somewhat tricky to do for a GADT.
Gershom Bazerman has some very nice slides on how to survive the process by
manual typechecking (much in the spirit of Oleg's meta-typechecking code
referenced by Stephen's follow up below)
He presented them at hac-phi this time around.
I will check with him to see if I can get permission to host them somewhere
and post a link to them here.
-Edward Kmett
On Fri, Jun 25, 2010 at 5:04 AM, <corentin.dupont at ext.mpsa.com> wrote:
>
> 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
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100625/22bf0e21/attachment.html
More information about the Haskell-Cafe
mailing list