[Haskell-cafe] Re: GATD and pattern matching
felipe.lessa at gmail.com
Thu Jun 10 19:46:18 EDT 2010
On Thu, Jun 10, 2010 at 11:14:42PM +0200, Daniel Fischer wrote:
> Show can work (should with the constraint on Equ), Eq is hairy.
> instance Show t => Show (Obs t) where
> show (Equ a b) = show a ++ " `Equal` " ++ show b
> show (Plus a b) = ...
> show (Konst x) = "Konst " ++ show x
> For an Eq instance, you have the problem that
> Equ (Konst True) (Konst False)
> Equ Player Turn
> both have the type Obs Bool, but have been constructed from different
> types, so you can't compare (Konst True) and Player.
> I don't see a nice way to work around that.
I didn't test, but something like this could work:
Equ :: (Show a, Eq a, Typeable a) => Obs a -> Obs a -> Obs Bool
(Equ a b) == (Equ c d) = eqTypeable (a,b) (c,d)
eqTypeable :: (Typeable a, Eq a, Typeable b, Eq b) => a -> b -> Bool
eqTypeable x y = case cast y of
Just y' -> x == y'
Nothing -> False
Maybe not ;).
More information about the Haskell-Cafe