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 -
On Thu, Jun 10, 2010 at 11:14 PM, Daniel Fischer
wrote:
> On Thursday 10 June 2010 22:01:38, Dupont Corentin wrote:
> > 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
>
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) => Ob
On Thursday 10 June 2010 22:01:38, Dupont Corentin wrote:
> 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 :: (Sho
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
>
On Fri, Jun 11, 2010 at 12:46 AM, Felipe Lessa wrote:
>
> 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
>
...or indeed:
eqTypeable x y = cast x == Just y
___
I don't know whether its a good name or not (the ===), but I have the
following in a generic utilities file I have, and I use it every now and
then.
(===) :: (Typeable a, Typeable b, Eq b) => a -> b -> Bool
(===) x y = cast x == Just y
(Notice you don't need Eq a in the context)
On 11 June 2010
Thanks all, it works fine (see below).
I lamentably try to make the same for show:
> showTypeable :: (Typeable a) => a -> String
> showTypeable x = case cast x of
> Just x' -> show x'
> Nothing -> ""
Because it really upsets me to add this show constraint
On Sat, Jun 12, 2010 at 12:13:14AM +0200, Dupont Corentin wrote:
> Thanks all, it works fine (see below).
>
> I lamentably try to make the same for show:
> > showTypeable :: (Typeable a) => a -> String
> > showTypeable x = case cast x of
> > Just x' -> show x'
> >