You're right, if you implement the type class independent of the value you'll end up with associating names with types.<br><br>I use it as an interface to your method actually - sorry I didn't make it clear enough.<br>
<br>So, something like this:<br><br>data NamedInt = NamedInt Int String<br><br>instance HasName NamedInt where<br> name (NamedInt _ n) = n<br> updateName n (NamedInt v _) = NamedInt v n<br><br>Now, if you want, you can have a Num instance for Named Int, redirect everything to the inner-int, and here you go. You can use NamedInt as a Num seamlessly.<br>
<br>Cheers,<br><br><div class="gmail_quote">On 20 March 2010 11:03, Stephen Tetley <span dir="ltr"><<a href="mailto:stephen.tetley@gmail.com">stephen.tetley@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hi Ozgur<br>
<br>
Doesn't that associate names with types rather than names with values though:<br>
<br>
instance HasName Int where<br>
name = "Int"<br>
<br>
<br>
> printWithName (1::Int)<br>
Int: 1<br>
<br>
> printWithName (70::Int)<br>
Int: 70<br>
<br>
I think the same is achievable with Data.Typeable / Data.Data although<br>
how to do it is somewhat buried...<br>
<br>
For associating names and values you'd still need to do it 'by hand'<br>
with something like<br>
<div class="im"><br>
data Named a = Named String a<br>
deriving (Show)<br>
<br>
</div>or<br>
<br>
type Named a = (String,a)<br>
<br>
Best wishes<br>
<font color="#888888"><br>
Stephen<br>
</font><div><div></div><div class="h5">_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Ozgur Akgun<br>