<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>
<title></title>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<meta http-equiv="Content-Style-Type" content="text/css"/>
</head>
<body>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">&gt; Date: Tue, 6 Mar 2007 14:43:03 -0500</span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">&gt; From: Jefferson Heard &lt;jeff@renci.org&gt;</span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">&gt; </span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">&gt; Usually, I can do this, but today, my brain is weak, and I'm just trying to </span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">&gt; get this piece of code out the door.&#160; My code looks like this:</span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">&gt; </span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">&gt; weight = sum (IntMap.elems (IntMap.intersectionWith </span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">&gt; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; (\x y -&gt; x*y) queryVector rationalProjection)) </span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">&gt; </span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">&gt; I know that this will work (ignoring indentation):</span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">&gt; </span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">&gt; sum $ IntMap.elems $ IntMap.intersectionWith (\x y -&gt; x*y) queryVector </span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">&gt; rationalProjection</span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">&gt; </span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">&gt; But why won't this?:</span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">&gt; </span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">&gt; sum . IntMap.elems . IntMap.IntersectionWith ...</span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt"><br />
</span></font></div>
<div align="left"><font face="Times New Roman" size="4"><span style="font-size:14pt">(.) is for function composition - both of its arguments must be functions, 
and of compatible types</span></font></div>
<div align="left"><font face="Times New Roman" size="4"><span style="font-size:14pt"><br />
</span></font></div>
<div align="left"><font face="Times New Roman" size="4"><span style="font-size:14pt">(.) :: (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c</span></font></div>
<div align="left"><font face="Times New Roman" size="4"><span style="font-size:14pt"><br />
</span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">IntMap.intersectionWith (\x y -&gt; x*y) queryVector rationalProjection</span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt"><br />
</span></font></div>
<div align="left"><font face="Times New Roman" size="4"><span style="font-size:14pt">has a type which is not a function (sorry, I don't have IntMap handy, so I 
can't reliably be more specific - I'm guessing the type is something like 
IntMap a).</span></font></div>
<div align="left"><font face="Times New Roman" size="4"><span style="font-size:14pt"><br />
</span></font></div>
<div align="left"><font face="Times New Roman" size="4"><span style="font-size:14pt">You can compose a whole string of functions a . b . c . d, but if you want 
to end up with a value, as here, then you eventually need to apply the 
resulting function to a value, which is where ($) comes in.&#160; When you're 
using (.) and ($) to build a complex expression, there's several possible 
combinations that will work, but assuming you're calculating a value 
rather than just building a complex function, there will be one or more 
($)s towards the right of the expression, and zero or more (.)s towards the 
left.</span></font></div>
<div align="left"><font face="Times New Roman" size="4"><span style="font-size:14pt"><br />
</span></font></div>
<div align="left"><font face="Times New Roman" size="4"><span style="font-size:14pt">(I'm sure somebody could come up with a more complex example where 
this doesn't hold, but this describes the typical function-pipeline case.)</span></font></div>
<div align="left"><font face="Times New Roman" size="4"><span style="font-size:14pt"><br />
</span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">&gt; Is there a difference between the &quot;elegance&quot; of function composition versus </span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">&gt; application?</span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt"><br />
</span></font></div>
<div align="left"><font face="Times New Roman" size="4"><span style="font-size:14pt">There's certainly a school of thought that considers it better style to 
compose all your functions and then apply them to your argument, which 
I have some sympathy with.&#160; I can also see circumstances where there 
may be practical advantages to using application throughout - it may 
make it easier to edit the pipeline if it uses application consistently.</span></font></div>
<div align="left"><font face="Times New Roman" size="4"><span style="font-size:14pt">-- </span></font></div>
<div align="left"><font face="Times New Roman" size="4"><span style="font-size:14pt">Iain Alexander&#160;&#160;&#160;&#160;&#160; ia@stryx.demon.co.uk</span></font></div>
<div align="left"></div>
</body>
</html>