<br><br><div class="gmail_quote">On Thu, Jun 10, 2010 at 11:14 PM, Daniel Fischer <span dir="ltr"><<a href="mailto:daniel.is.fischer@web.de">daniel.is.fischer@web.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">On Thursday 10 June 2010 22:01:38, Dupont Corentin wrote:<br>
> Hello Maciej,<br>
> i tried this out, but it didn't worked.<br>
><br>
> Daniel,<br>
><br>
> I added a (Show a) constraint to Equal:<br>
> > data Obs a where<br>
> > Player :: Obs Integer<br>
> > Turn :: Obs Integer<br>
> > Official :: Obs Bool<br>
> > Equ :: (Show a, Eq a) => Obs a -> Obs a -> Obs Bool<br>
><br>
> --woops!!<br>
><br>
> > Plus :: (Num a) => Obs a -> Obs a -> Obs a<br>
> > Time :: (Num a) => Obs a -> Obs a -> Obs a<br>
> > Minus :: (Num a) => Obs a -> Obs a -> Obs a<br>
> > Konst :: a -> Obs a<br>
> > And :: Obs Bool -> Obs Bool -> Obs Bool<br>
> > Or :: Obs Bool -> Obs Bool -> Obs Bool<br>
><br>
> It works for the Show instance, but not Eq.<br>
> By the way, shouldn't the Show constraint be on the instance and not on<br>
> the datatype declaration?<br>
<br>
</div>Can't be here, because of<br>
<div class="im"> Equ :: Obs a -> Obs a -> Obs Bool<br>
<br>
</div>You forget the parameter a, and you can't recover it in the instance<br>
declaration. So you have to provide the Show instance for a on<br>
construction, i.e. put the constraint on the data constructor.<br>
<div class="im"><br></div></blockquote><div><br>Anyway, is my Obs construction revelant at all? What i want to do is to provide an EDSL to the user to test things about the state of the game (for the Nomic game i'm making). Obs will be then embedded in another EDSL to construct Nomic's rules.<br>
<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">
> I'd prefer to keep the datatype as generic as possible...<br>
><br>
> There is really no way to make my Obs datatype an instance of Eq and<br>
> Show??<br>
<br>
</div>Show can work (should with the constraint on Equ), Eq is hairy.<br>
<div class="im"><br>
instance Show t => Show (Obs t) where<br>
</div> show (Equ a b) = show a ++ " `Equal` " ++ show b<br>
show (Plus a b) = ...<br>
show (Konst x) = "Konst " ++ show x<br>
...<br>
<br>
For an Eq instance, you have the problem that<br>
<br>
Equ (Konst True) (Konst False)<br>
and<br>
Equ Player Turn<br>
<br>
both have the type Obs Bool, but have been constructed from different<br>
types, so you can't compare (Konst True) and Player.<br>
I don't see a nice way to work around that.<br>
<div><div></div><div class="h5"><br></div></div></blockquote><div><br>These is a dirty way: compare the string representation of the rules. They should be unique.<br> </div></div>Corentin<br>