<!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">> 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">> From: Jefferson Heard <jeff@renci.org></span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">> </span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">> 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">> get this piece of code out the door.  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">> </span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">> 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">>                      (\x y -> x*y) queryVector rationalProjection)) </span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">> </span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">> 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">> </span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">> sum $ IntMap.elems $ IntMap.intersectionWith (\x y -> x*y) queryVector </span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">> rationalProjection</span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">> </span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">> 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">> </span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">> 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 -> c) -> (a -> b) -> a -> 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 -> 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.  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">> Is there a difference between the "elegance" of function composition versus </span></font></div>
<div align="left"><font face="Times New Roman" color="#ff0000" size="4"><span style="font-size:14pt">> 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.  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      ia@stryx.demon.co.uk</span></font></div>
<div align="left"></div>
</body>
</html>