<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=windows-1250">


<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<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;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        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;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        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;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:"Courier New";}
span.searchword1
        {mso-style-name:searchword1;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.Section1
        {page:Section1;}
 /* List Definitions */
 @list l0
        {mso-list-id:199393246;
        mso-list-type:hybrid;
        mso-list-template-ids:1297507736 201916431 201916441 201916443 201916431 201916441 201916443 201916431 201916441 201916443;}
@list l0:level1
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
-->
</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-AU link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>Hi,<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>I
was wondering what the best way to implement Natural number would be. Is there
a package which already does this?<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>Here
are some options:<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'><o:p>&nbsp;</o:p></span></p>

<p class=MsoListParagraph style='text-indent:-18.0pt;mso-list:l0 level1 lfo1'><![if !supportLists]><span
style='font-size:10.0pt;font-family:"Courier New"'><span style='mso-list:Ignore'>1.<span
style='font:7.0pt "Times New Roman"'>&nbsp; </span></span></span><![endif]><span
style='font-size:10.0pt;font-family:"Courier New"'>Don&#8217;t bother. Just use
Integer.<o:p></o:p></span></p>

<p class=MsoListParagraph style='text-indent:-18.0pt;mso-list:l0 level1 lfo1'><![if !supportLists]><span
style='font-size:10.0pt;font-family:"Courier New"'><span style='mso-list:Ignore'>2.<span
style='font:7.0pt "Times New Roman"'>&nbsp; </span></span></span><![endif]><span
style='font-size:10.0pt;font-family:"Courier New"'>Use the type <o:p></o:p></span></p>

<p class=MsoListParagraph><span style='font-size:10.0pt;font-family:"Courier New"'>data
Natural = Zero | Succ !Natural<o:p></o:p></span></p>

<p class=MsoListParagraph style='text-indent:-18.0pt;mso-list:l0 level1 lfo1'><![if !supportLists]><span
style='font-size:10.0pt;font-family:"Courier New"'><span style='mso-list:Ignore'>3.<span
style='font:7.0pt "Times New Roman"'>&nbsp; </span></span></span><![endif]><span
style='font-size:10.0pt;font-family:"Courier New"'>Use the following definition
taken from the Gentle Introduction to Haskell 98<o:p></o:p></span></p>

<p class=MsoListParagraph><span style='font-size:10.0pt;font-family:"Courier New"'>newtype
Natural = MakeNatural Integer<o:p></o:p></span></p>

<p class=MsoListParagraph><span style='font-size:10.0pt;font-family:"Courier New"'>toNatural ::Integer-&gt;
Integer<o:p></o:p></span></p>

<p class=MsoListParagraph><span style='font-size:10.0pt;font-family:"Courier New"'>toNatural
x | x &lt; 0 = error &#8220;Can&#8217;t create negative naturals!&#8221;<o:p></o:p></span></p>

<p class=MsoListParagraph><span style='font-size:10.0pt;font-family:"Courier New"'>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
| otherwise = MakeNatural x<o:p></o:p></span></p>

<p class=MsoListParagraph><span style='font-size:10.0pt;font-family:"Courier New"'>fromNatural
:: Natural -&gt; Integer<o:p></o:p></span></p>

<p class=MsoListParagraph><span style='font-size:10.0pt;font-family:"Courier New"'>fromNatural
(MakeNatural i) = i<o:p></o:p></span></p>

<p class=MsoListParagraph><span style='font-size:10.0pt;font-family:"Courier New"'><o:p>&nbsp;</o:p></span></p>

<p class=MsoListParagraph><span style='font-size:10.0pt;font-family:"Courier New"'>and
then...<o:p></o:p></span></p>

<p class=MsoListParagraph><span style='font-size:10.0pt;font-family:"Courier New"'><o:p>&nbsp;</o:p></span></p>

<p class=MsoListParagraph><span style='font-size:10.0pt;font-family:"Courier New"'>instance
Num Natural where<o:p></o:p></span></p>

<p class=MsoListParagraph><span style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;
fromInteger = toNAtural<o:p></o:p></span></p>

<p class=MsoListParagraph><span style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;
x + y&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = toNatural (fromNatural x +
fromNatural y)<o:p></o:p></span></p>

<p class=MsoListParagraph><span style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;
x &#8211; y &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= etc..<o:p></o:p></span></p>

<p class=MsoListParagraph><span style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;
x * y&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = etc...<o:p></o:p></span></p>

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

<p class=MsoNormal>Which method is best? So far, I&#8217;ve been picking option
#1 &#8211; just leaving things as they are and using Integer to keep things
simple.<o:p></o:p></p>

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

<p class=MsoNormal>I&#8217;ve got that feeling that [2] would be fast and [3]
would be slow. Comment appreciated on the merits of each.<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><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>Mark Spezzano<o:p></o:p></p>

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

</div>

</body>

</html>
<BR>

<P><FONT SIZE=2>No virus found in this outgoing message.<BR>
Checked by AVG.<BR>
Version: 7.5.557 / Virus Database: 270.11.12/1998 - Release Date: 12/03/2009 6:23 PM<BR>
</FONT> </P>