<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> </o:p></p>
<p class=MsoNormal>Typing up and running (via Hugs) the examples in Wadler’s
excellent “Monads for functional programming” (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 “show” function error:<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>ERROR - Cannot find "show" function for:<o:p></o:p></p>
<p class=MsoNormal>*** Expression : eval answer<o:p></o:p></p>
<p class=MsoNormal>*** Of type : Int -> (Int,Int)<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>I can find lots of nice text about extending data for “show”
(including the miraculous “Deriving”) but… I’m showing
my Haskell newbie roots by utterly failing to understand how to do this of a “higher-order”
type (my best guess for the right term for the type Int -> (Int, Int)).<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>It’d be a big help if somebody could tell me either:<o:p></o:p></p>
<p class=MsoNormal><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'>a)<span
style='font:7.0pt "Times New Roman"'> </span></span><![endif]>It’s
obvious, you moron, just <insert Haskell code here><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"'> </span></span><![endif]>It’s
impossible, you moron, you’re trying to violate the <insert Haskell
rule here><o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>Here’ my code:<o:p></o:p></p>
<p class=MsoNormal><o:p> </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 -> (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 -> 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>
let (b, z) = eval u y in<o:p></o:p></p>
<p class=MsoNormal>
(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> </o:p></p>
<p class=MsoNormal>I get the “ERROR” message when I type “eval
answer” at the Hugs prompt.<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>Thanks!<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>Tom Titchener<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
</div>
</body>
</html>