<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7653.38">
<TITLE>Multi-parameter Type Class</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<P><FONT SIZE=2>Hi all,<BR>
<BR>
I've been trying to refactor my tree conversion code to make<BR>
better use of type classes; and I've discovered multi-parameter<BR>
type classes and functional dependencies. I have a class with a<BR>
function a2b, and I'd like "map" to be used when it's a list of<BR>
type a.<BR>
<BR>
I've created a simple failing example:<BR>
<BR>
data Foo = Foo Bar deriving(Show)<BR>
data Bar = Bar String deriving(Show)<BR>
<BR>
class ZOT a b | a -> b where<BR>
zot :: a -> b<BR>
<BR>
instance ZOT Foo Integer where<BR>
zot x = 17<BR>
<BR>
instance ZOT Bar String where<BR>
zot x = "Eighteen"<BR>
<BR>
instance ZOT [x] [y] where -- This bit<BR>
zot xs = map zot xs -- fails<BR>
<BR>
main = do print $ zot $ Foo $ Bar "Blah"<BR>
print $ zot $ Bar "Blah"<BR>
print $ zot $ [Bar "Blah", Bar "Blah"] -- No map here please<BR>
<BR>
I know this would work if the third instance of zot<BR>
explicitly took [Bar] and [String]. Can I not instead generalise<BR>
for all the ADTs in my tree in the way I've outlined? Must I<BR>
instantiate for the type of each list pair?<BR>
<BR>
Cheers,<BR>
Paul<BR>
</FONT>
</P>
</BODY>
</HTML>