No subject
Thu Jul 5 12:38:43 CEST 2012
age Player are all completely distinct types and may have different behavio=
r--there's no way for it to "know" that they all have the sam=
e representation that only contains a String.<br>
<br>The derived Typeable instance for "Message m" is really a der=
ived instance of "Typeable1 Message" along with the generic insta=
nce "(Typeable1 f, Typeable a) =3D> Typeable (m a)" in Data.Ty=
peable.<br>
<br>So you need to specify the type of message you want, or drop the type p=
arameter from Message.<br><br>A simpler answer, though, would just be to pu=
t the functions in the typeclass.<br><br>class Event e where<br>=A0=A0=A0 v=
iewEvent :: e -> IO ()<br>
<br>instance Event Player where<br>=A0=A0=A0 viewEvent (Player a) =3D putSt=
rLn $ show a<br>instance Event (Message m) where<br>=A0=A0=A0 viewEvent (Me=
ssage s) =3D putStrLn s<br><br>In this case, the instance makes it clear th=
at the type parameter is irrelevant and puts no constraints on it.=A0 And t=
he type of viewEvent is exactly the same as you were asking for: Event e =
=3D> e -> IO ().<br>
<br>=A0 -- ryan<br><br><div class=3D"gmail_quote">On Mon, Sep 10, 2012 at 3=
:06 PM, Corentin Dupont <span dir=3D"ltr"><<a href=3D"mailto:corentin.du=
pont at gmail.com" target=3D"_blank">corentin.dupont at gmail.com</a>></span> =
wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">Hi Stephen,<br>I wasn't aware of Data.Dy=
namic.<br>I tried:<br><br><i>viewEvent :: Dynamic -> IO ()<br>viewEvent =
event =3D do<br>
=A0=A0 case fromDynamic event of<br>=A0=A0=A0=A0=A0=A0=A0 Nothing -> ret=
urn ()<div class=3D"im"><br>=A0=A0=A0=A0=A0=A0=A0 Just (Message s) -> pu=
tStrLn $ show s</div></i><br>
<br>But still got the same error (Ambiguous type variable `t0' in the c=
onstraint:=A0 (Typeable t0) arising from a use of `fromDynamic')...<br>=
<br>Best,<br>Corentin<div class=3D"HOEnZb"><div class=3D"h5"><br><br><br><d=
iv class=3D"gmail_quote">
On Mon, Sep 10, 2012 at 11:33 PM, Stephen Tetley <span dir=3D"ltr"><<a h=
ref=3D"mailto:stephen.tetley at gmail.com" target=3D"_blank">stephen.tetley at gm=
ail.com</a>></span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">Whilst dynamic typing isn't idiomatic fo=
r Haskell, it seems like<br>
you've decided you want it. So why not use Data.Dynamic rather than<br>
roll you're own dynamic typing with Typeable?<br>
</blockquote></div><br>
</div></div><br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href=3D"mailto:Haskell-Cafe at haskell.org">Haskell-Cafe at haskell.org</a><br=
>
<a href=3D"http://www.haskell.org/mailman/listinfo/haskell-cafe" target=3D"=
_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br>
--14dae9340983b2f17904c960f7e4--
More information about the Haskell-Cafe
mailing list