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 ().<span class=3D"HOEnZb"><font color=3D"#888888"><br>
<br>=A0 -- ryan<br><br></font></span><div class=3D"gmail_quote"><div><div c=
lass=3D"h5">On Mon, Sep 10, 2012 at 3:06 PM, Corentin Dupont <span dir=3D"l=
tr"><<a href=3D"mailto:corentin.dupont at gmail.com" target=3D"_blank">core=
ntin.dupont at gmail.com</a>></span> wrote:<br>
</div></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;bo=
rder-left:1px #ccc solid;padding-left:1ex"><div><div class=3D"h5">Hi Stephe=
n,<br>I wasn't aware of Data.Dynamic.<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><br>=A0=A0=A0=A0=A0=A0=A0 Just (Message s) -> putStrLn $ 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><div><br><br><br><div 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></div></div><div class=3D"im">_____________________________=
__________________<br>
Haskell-Cafe mailing list<br>
<a href=3D"mailto:Haskell-Cafe at haskell.org" target=3D"_blank">Haskell-Cafe@=
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></div></blockquote></div><br>
</blockquote></div><br>
--14dae934098f3b17b804c9611782--
More information about the Haskell-Cafe
mailing list