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 &quot;Message m&quot; is really a der=
ived instance of &quot;Typeable1 Message&quot; along with the generic insta=
nce &quot;(Typeable1 f, Typeable a) =3D&gt; Typeable (m a)&quot; in Data.Ty=
<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 -&gt; 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&gt; e -&gt; 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">&lt;<a href=3D"mailto:corentin.du=
pont at" target=3D"_blank"> at</a>&gt;</span> =
<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&#39;t aware of Data.Dy=
namic.<br>I tried:<br><br><i>viewEvent :: Dynamic -&gt; IO ()<br>viewEvent =
event =3D do<br>
=A0=A0 case fromDynamic event of<br>=A0=A0=A0=A0=A0=A0=A0 Nothing -&gt; ret=
urn ()<div class=3D"im"><br>=A0=A0=A0=A0=A0=A0=A0 Just (Message s) -&gt; pu=
tStrLn $ show s</div></i><br>
<br>But still got the same error (Ambiguous type variable `t0&#39; in the c=
onstraint:=A0 (Typeable t0) arising from a use of `fromDynamic&#39;)...<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">&lt;<a h=
ref=3D"mailto:stephen.tetley at" target=3D"_blank">stephen.tetley at gm=</a>&gt;</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&#39;t idiomatic fo=
r Haskell, it seems like<br>
you&#39;ve decided you want it. So why not use Data.Dynamic rather than<br>
roll you&#39;re own dynamic typing with Typeable?<br>
Haskell-Cafe mailing list<br>
<a href=3D"mailto:Haskell-Cafe at">Haskell-Cafe at</a><br=
<a href=3D"" target=3D"=


More information about the Haskell-Cafe mailing list