<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:"Franklin Gothic Book";
        panose-1:2 11 5 3 2 1 2 2 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="2050" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal>I'm new to Haskell and functional programming; have been
exploring the fixed-point combinator based on the exercise in the HSOE book.&nbsp;
Having an odd issue with typing in ghci which I don't understand - maybe it's
to do with section <span lang=EN>3.4.5.&nbsp;&quot;Type defaulting in GHCi&quot;
but I don't really grok that yet&#8230;<o:p></o:p></span></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>(BTW, an unrelated question:&nbsp; is there a good reference
where I can understand the precendence/associativity rules for Haskell?&nbsp; I
continually find myself needing lots of parens before expressions behave as I
expect, and get very confused trying to use the $ operator - usually resorting
to lots of parens again :-)<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>My typing question might boil down to this simple example,
though my original example follows:<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>-- Why don't these (particularly g and g') all have the same
type?<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>Prelude&gt; :t (\x -&gt; x+1)<o:p></o:p></p>

<p class=MsoNormal>(\x -&gt; x+1) :: (Num a) =&gt; a -&gt; a<o:p></o:p></p>

<p class=MsoNormal>Prelude&gt; let g = (\x -&gt; x+1)<o:p></o:p></p>

<p class=MsoNormal>Prelude&gt; :t g<o:p></o:p></p>

<p class=MsoNormal>g :: Integer -&gt; Integer<o:p></o:p></p>

<p class=MsoNormal>Prelude&gt; let g' x = x + 1<o:p></o:p></p>

<p class=MsoNormal>Prelude&gt; :t g'<o:p></o:p></p>

<p class=MsoNormal>g' :: (Num a) =&gt; a -&gt; a<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>-- Here's my original fixed-point combinator example:<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>Prelude&gt; let fix f = f (fix f)<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>-- here's a silly (but working) implementation of length
using fix:<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>Prelude&gt;&nbsp; fix (\g xs -&gt; if xs == [] then 0 else
(1 + g (tail xs))) [1,2,3,4]<o:p></o:p></p>

<p class=MsoNormal>4<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>-- so I examine the types of the parts, which seems fine:<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>Prelude&gt; :t fix (\g xs -&gt; if xs == [] then 0 else (1 +
g (tail xs)))<o:p></o:p></p>

<p class=MsoNormal>&#8230; &nbsp;:: (Num t, Eq a) =&gt; [a] -&gt; t<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>Prelude&gt; :t (\g xs -&gt; if xs == [] then 0 else (1 + g
(tail xs)))<o:p></o:p></p>

<p class=MsoNormal>&#8230; :: (Num t, Eq a) =&gt; ([a] -&gt; t) -&gt; [a] -&gt;
t<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>-- but now I try to bind the anonymous function to a name<o:p></o:p></p>

<p class=MsoNormal>-- this seems to get the types wrong and no longer works as
I expect:<o:p></o:p></p>

<p class=MsoNormal>&nbsp;<o:p></o:p></p>

<p class=MsoNormal>Prelude&gt; let lenstep = (\g xs -&gt; if xs == [] then 0
else (1 + g (tail xs)))<o:p></o:p></p>

<p class=MsoNormal>Prelude&gt; :t lenstep<o:p></o:p></p>

<p class=MsoNormal>lenstep :: ([()] -&gt; Integer) -&gt; [()] -&gt; Integer<o:p></o:p></p>

<p class=MsoNormal>Prelude&gt; :t fix lenstep<o:p></o:p></p>

<p class=MsoNormal>fix lenstep :: [()] -&gt; Integer<o:p></o:p></p>

<p class=MsoNormal>Prelude&gt; let len' = fix (\g xs -&gt; if xs == [] then 0
else (1 + g (tail xs)))<o:p></o:p></p>

<p class=MsoNormal>Prelude&gt; :t len'<o:p></o:p></p>

<p class=MsoNormal>len' :: [()] -&gt; Integer<o:p></o:p></p>

<p class=MsoNormal>Prelude&gt;<o:p></o:p></p>

<p class=MsoNormal>Prelude&gt; len' [1,2,3,4]<o:p></o:p></p>

<p class=MsoNormal>&lt;interactive&gt;:1:12:<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp; No instance for (Num ())<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; arising from the literal `4'
at &lt;interactive&gt;:1:12<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp; Possible fix: add an instance declaration
for (Num ())<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp; In the expression: 4<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp; In the first argument of `len'', namely
`[1, 2, 3, 4]'<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp; In the expression: len' [1, 2, 3, 4]<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>-- maybe this is just me not understanding name binding
properly; it seems to work if I do it this way:<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>Prelude&gt; let lenstep' g xs = (if xs == [] then 0 else (1
+ g (tail xs)))<o:p></o:p></p>

<p class=MsoNormal>Prelude&gt; :t lenstep'<o:p></o:p></p>

<p class=MsoNormal>lenstep' :: (Eq a, Num t) =&gt; ([a] -&gt; t) -&gt; [a]
-&gt; t<o:p></o:p></p>

<p class=MsoNormal>Prelude&gt; :t fix lenstep'<o:p></o:p></p>

<p class=MsoNormal>fix lenstep' :: (Eq a, Num t) =&gt; [a] -&gt; t<o:p></o:p></p>

<p class=MsoNormal>Prelude&gt; fix lenstep' [1,2,3,4]<o:p></o:p></p>

<p class=MsoNormal>4<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>-- but what's the difference?<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>Cheers,<o:p></o:p></p>

<p class=MsoNormal>Patrick<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<table class=MsoNormalTable border=0 cellpadding=0 width="100%"
 style='width:100.0%'>
 <tr>
  <td valign=top style='padding:.75pt .75pt .75pt .75pt'>
  <div>
  <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Franklin Gothic Book","sans-serif";
  color:gray'><a href="mailto:Patrick.Surry@portraitsoftware.com"><b><span
  style='color:gray'>Patrick.Surry</span></b><span style='color:gray'>@portraitsoftware.com</span></a>,
  VP Technology <o:p></o:p></span></p>
  </div>
  <div>
  <p class=MsoNormal><b><span style='font-size:9.0pt;font-family:"Franklin Gothic Book","sans-serif";
  color:gray'>Tel:</span></b><span style='font-size:9.0pt;font-family:"Franklin Gothic Book","sans-serif";
  color:gray'> (617) 457 5230 <b>Mob:</b> (857) 919 1700 <b>Fax:</b> (617) 457
  5299 <a
  href="http://maps.google.com/maps?f=q&amp;hl=en&amp;q=125+Summer+St,+Boston,+MA+02110&amp;ie=UTF8&amp;z=15&amp;ll=42.353153,-71.057296&amp;spn=0.022644,0.054245&amp;om=1&amp;iwloc=A"
  title="125 Summer St, 16th Floor, Boston, MA, 02210"><b><span
  style='color:gray'>Map</span></b></a> <o:p></o:p></span></p>
  </div>
  <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Franklin Gothic Book","sans-serif";
  color:gray'><o:p>&nbsp;</o:p></span></p>
  <div>
  <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Franklin Gothic Book","sans-serif";
  color:gray'>Portrait Software introduces <a
  href="http://www.portraitsoftware.com/Products/portrait_campaign_manager"
  title="Learn more..."><span style='color:blue'>Portrait Campaign Manager</span></a>:<o:p></o:p></span></p>
  </div>
  <div>
  <p class=MsoNormal><span style='font-size:9.0pt;font-family:"Franklin Gothic Book","sans-serif";
  color:gray'>Easy, integrated campaign management for automated and highly
  targeted outbound marketing<o:p></o:p></span></p>
  </div>
  </td>
  <td valign=top style='padding:.75pt .75pt .75pt .75pt'>
  <p class=MsoNormal align=center style='text-align:center'><a
  href="http://www.portraitsoftware.com/"
  title="http://www.portraitsoftware.com/"><span style='font-size:10.0pt;
  font-family:"Franklin Gothic Book","sans-serif";color:blue;text-decoration:
  none'><img border=0 width=80 height=80 id="_x0000_i1026"
  src="http://supportcentre.portraitsoftware.com/Vmail/emailfooter/balloon.gif"
  alt="http://supportcentre.portraitsoftware.com/Vmail/emailfooter/balloon.gif"></span></a><span
  style='font-size:10.0pt;font-family:"Franklin Gothic Book","sans-serif";
  color:gray'><o:p></o:p></span></p>
  </td>
  <td valign=top style='padding:.75pt .75pt .75pt .75pt'>
  <div>
  <p class=MsoNormal align=right style='text-align:right'><span
  style='font-size:9.0pt;font-family:"Franklin Gothic Book","sans-serif";
  color:gray'><a href="http://www.portraitsoftware.com/"
  title="http://www.portraitsoftware.com/"><span style='font-size:11.0pt;
  font-family:"Calibri","sans-serif";color:windowtext;text-decoration:none'><span
  style='font-size:9.0pt;font-family:"Franklin Gothic Book","sans-serif";
  color:blue'><img border=0 width=150 height=50 id="_x0000_i1025"
  src="http://supportcentre.portraitsoftware.com/Vmail/emailfooter/portrait_software_logo.gif"
  alt="http://supportcentre.portraitsoftware.com/Vmail/emailfooter/portrait_software_logo.gif"></span></span><span
  style='font-size:12.0pt;font-family:"Times New Roman","serif";color:blue'><o:p></o:p></span></a></span></p>
  <div>
  <p class=MsoNormal align=right style='text-align:right'><u><span
  style='font-size:9.0pt;font-family:"Franklin Gothic Book","sans-serif";
  color:gray'><a href="http://www.portraitsoftware.com/"
  title="http://www.portraitsoftware.com/"><span style='color:gray'>www.portraitsoftware.com</span><span
  style='font-size:12.0pt;font-family:"Times New Roman","serif";color:gray;
  text-decoration:none'><o:p></o:p></span></a></span></u></p>
  </div>
  <p class=MsoNormal align=right style='text-align:right'><span
  style='font-size:9.0pt;font-family:"Franklin Gothic Book","sans-serif";
  color:gray'><o:p>&nbsp;</o:p></span></p>
  </div>
  </td>
 </tr>
</table>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>


<BR>
________________________________________________________________________<BR>
DISCLAIMER: This e-mail is intended only for the addressee named above. As this e-mail may contain confidential or privileged information, if you are not the named addressee, you are not authorised to retain, read, copy or disseminate this message or any part of it. If you received this email in error, please notify the sender and delete the message from your computer.<BR>
</body>

</html>