<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)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 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.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0in;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:.5in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.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;}
 /* List Definitions */
 @list l0
        {mso-list-id:1311515682;
        mso-list-type:hybrid;
        mso-list-template-ids:-1656737954 1636992882 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l0:level1
        {mso-level-number-format:alpha-lower;
        mso-level-text:"%1\)";
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:.75in;
        text-indent:-.25in;}
ol
        {margin-bottom:0in;}
ul
        {margin-bottom:0in;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</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><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>Typing up and running (via Hugs) the examples in Wadler&#8217;s
excellent &#8220;Monads for functional programming&#8221; (here: <a
href="http://homepages.inf.ed.ac.uk/wadler/papers/marktoberdorf/baastad.pdf">http://homepages.inf.ed.ac.uk/wadler/papers/marktoberdorf/baastad.pdf</a>)
I hit the inevitable &#8220;show&#8221; function error:<o:p></o:p></p>

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

<p class=MsoNormal>ERROR - Cannot find &quot;show&quot; function for:<o:p></o:p></p>

<p class=MsoNormal>*** Expression : eval answer<o:p></o:p></p>

<p class=MsoNormal>*** Of type&nbsp;&nbsp;&nbsp; : Int -&gt; (Int,Int)<o:p></o:p></p>

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

<p class=MsoNormal>I can find lots of nice text about extending data for &#8220;show&#8221;
(including the miraculous &#8220;Deriving&#8221;) but&#8230; I&#8217;m showing
my Haskell newbie roots by utterly failing to understand how to do this of a &#8220;higher-order&#8221;
type (my best guess for the right term for the type Int -&gt; (Int, Int)).<o:p></o:p></p>

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

<p class=MsoNormal>It&#8217;d be a big help if somebody could tell me either:<o:p></o:p></p>

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

<p class=MsoListParagraph style='margin-left:.75in;text-indent:-.25in;
mso-list:l0 level1 lfo1'><![if !supportLists]><span style='mso-list:Ignore'>a)<span
style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><![endif]>It&#8217;s
obvious, you moron, just &lt;insert Haskell code here&gt;<br>
<br>
or<br>
<br>
<o:p></o:p></p>

<p class=MsoListParagraph style='margin-left:.75in;text-indent:-.25in;
mso-list:l0 level1 lfo1'><![if !supportLists]><span style='mso-list:Ignore'>b)<span
style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><![endif]>It&#8217;s
impossible, you moron, you&#8217;re trying to violate the &lt;insert Haskell
rule here&gt;<o:p></o:p></p>

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

<p class=MsoNormal>Here&#8217; my code:<o:p></o:p></p>

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

<p class=MsoNormal>data Term = Con Int | Div Term Term<o:p></o:p></p>

<p class=MsoNormal>type M a = State -&gt; (a, State) -- higher-order type, e.g.
function type<o:p></o:p></p>

<p class=MsoNormal>type State = Int -- type synonym<o:p></o:p></p>

<p class=MsoNormal>eval :: Term -&gt; M Int<o:p></o:p></p>

<p class=MsoNormal>eval (Con a) x = (a, x)<o:p></o:p></p>

<p class=MsoNormal>eval (Div t u) x = let (a, y) = eval t x in<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
let (b, z) = eval u y in<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
(a `div` b, z + 1)<o:p></o:p></p>

<p class=MsoNormal>answer, error :: Term<o:p></o:p></p>

<p class=MsoNormal>answer = (Div(Div(Con 1972)(Con 2))(Con 23))<o:p></o:p></p>

<p class=MsoNormal>error = (Div(Con 1)(Con 0))<o:p></o:p></p>

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

<p class=MsoNormal>I get the &#8220;ERROR&#8221; message when I type &#8220;eval
answer&#8221; at the Hugs prompt.<o:p></o:p></p>

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

<p class=MsoNormal>Thanks!<o:p></o:p></p>

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

<p class=MsoNormal>Tom Titchener<o:p></o:p></p>

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

</div>

</body>

</html>