
Hello Maciej, i tried this out, but it didn't worked. Daniel, I added a (Show a) constraint to Equal:
data Obs a where Player :: Obs Integer Turn :: Obs Integer Official :: Obs Bool Equ :: (Show a, Eq a) => Obs a -> Obs a -> Obs Bool --woops!! 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 Konst :: a -> Obs a And :: Obs Bool -> Obs Bool -> Obs Bool Or :: Obs Bool -> Obs Bool -> Obs Bool
It works for the Show instance, but not Eq. By the way, shouldn't the Show constraint be on the instance and not on the datatype declaration? I'd prefer to keep the datatype as generic as possible... There is really no way to make my Obs datatype an instance of Eq and Show?? I searched around a way to add type information on the pattern match like:
instance Show t => Show (Obs t) where show (Equal (a::Obs t) (b::Obs t)) = (show a) ++ " Equal " ++ (show b) show (Plus a b) = (show a) ++ " Plus " ++ (show b)
But it doesn't work.
thanks for your help,
Corentin
On Thu, Jun 10, 2010 at 2:47 AM, Maciej Piechotka
On Wed, 2010-06-09 at 22:28 +0200, Dupont Corentin wrote:
Thanks for your response.
How would you do it? I design this GATD for a game i'm making:
data Obs a where Player :: Obs Integer Turn :: Obs Integer Official :: Obs Bool Equ :: Obs a -> Obs a -> Obs Bool --woops!! 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 Konst :: a -> Obs a
Actually woops is here. Make it for example
Const :: (Show a, Eq a, ...) => a -> Obs a
And :: Obs Bool -> Obs Bool -> Obs Bool Or :: Obs Bool -> Obs Bool -> Obs Bool
For example I can design an Observable like that:
myObs = Player `Equ` (Konst 1) `And` Official
These Observables will then be processed during gameplay.
I would like to be able to do in ghci:
show myObs Player `Equ` (Konst 1) `And` Official
and:
myObs == myObs True
Regards
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe