<!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 &quot;map&quot; 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&nbsp;&nbsp;&nbsp; deriving(Show)<BR>
data Bar = Bar String deriving(Show)<BR>
<BR>
class ZOT a b | a -&gt; b where<BR>
&nbsp; zot :: a -&gt; b<BR>
<BR>
instance ZOT Foo Integer where<BR>
&nbsp; zot x = 17<BR>
<BR>
instance ZOT Bar String where<BR>
&nbsp; zot x = &quot;Eighteen&quot;<BR>
<BR>
instance ZOT [x] [y] where&nbsp;&nbsp; -- This bit<BR>
&nbsp; zot xs = map zot xs&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- fails<BR>
<BR>
main = do print $ zot $ Foo $ Bar &quot;Blah&quot;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print $ zot $ Bar &quot;Blah&quot;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print $ zot $ [Bar &quot;Blah&quot;, Bar &quot;Blah&quot;] -- 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>