PS.<br>Prelude Data.List Data.Number.Natural&gt; genericLength [1..] &gt; (10 :: Natural)<br>True<br><br><br><div><span class="gmail_quote">On 9/24/07, <b class="gmail_sendername">Lennart Augustsson</b> &lt;<a href="mailto:lennart@augustsson.net">
lennart@augustsson.net</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Since natural numbers are trivial to implement (inefficiently) I took 15 minutes and added them to my numbers package in Hackage.
<br><a href="http://hackage.haskell.org/cgi-bin/hackage-scripts/package/numbers-2007.9.24" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://hackage.haskell.org/cgi-bin/hackage-scripts/package/numbers-2007.9.24
</a><br><span class="sg"><br>&nbsp; -- Lennart</span><div><span class="e" id="q_115399088fd9a701_2"><br><br><div><span class="gmail_quote">On 9/24/07, <b class="gmail_sendername">Andrew Coppin</b> &lt;<a href="mailto:andrewcoppin@btinternet.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
andrewcoppin@btinternet.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Neil Mitchell wrote:<br>&gt; Hi<br>&gt;<br>&gt;<br>&gt;&gt;&gt; Pretty much, yes.<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;<br>&gt;&gt; So I just need to write<br>&gt;&gt;<br>&gt;&gt;&nbsp;&nbsp; newtype LazyNatural = LazyNatural [()]<br>&gt;&gt;
<br>&gt;<br>&gt; or<br>&gt;<br>&gt; data Nat = Zero | Succ Nat<br>&gt;<br>&gt; it&#39;s your choice really.<br>&gt;<br><br>I&#39;m guessing there&#39;s going to be fairly minimal performance difference.<br>(Or maybe there is. My way uses a few additional pointers. But it also
<br>allows me to elegantly recycle existing Prelude list functions, so...)<br><br>&gt;&gt; and then add some suitable instances. ;-)<br>&gt;&gt;<br>&gt;<br>&gt; Yes. Lots of them. Lots of instances and lots of methods.<br>

&gt;<br>&gt;<br>&gt;&gt; Hey, the &quot;length&quot; function would then just be<br>&gt;&gt;<br>&gt;&gt;&nbsp;&nbsp; ln_length :: [x] -&gt; LazyNatural<br>&gt;&gt;&nbsp;&nbsp; ln_length = LazyNatural . map (const ())<br>&gt;&gt;<br>&gt;&gt; Ooo, that&#39;s hard.
<br>&gt;&gt;<br>&gt;<br>&gt; Nope, its really easy. Its just quite a bit of work filling in all the<br>&gt; instances. I bet you can&#39;t do it and upload the results to hackage<br>&gt; within 24 hours :-)<br>&gt;<br><br>

*ALL* the instances? No.<br><br>A small handful of them? Sure. How about this...<br><br><br><br>module LazyNatural (LazyNatural ()) where<br><br>import Data.List<br><br>newtype LazyNatural = LN [()]<br><br>instance Show LazyNatural where
<br>&nbsp;&nbsp;show (LN x) = &quot;LN &quot; ++ show (length x)<br><br>instance Eq LazyNatural where<br>&nbsp;&nbsp;(LN x) == (LN y) = x == y<br><br><br>instance Ord LazyNatural where<br>&nbsp;&nbsp;compare (LN x) (LN y) = raw_compare x y<br><br>raw_compare ([])&nbsp;&nbsp;(_:_) = LT
<br>raw_compare ([])&nbsp;&nbsp;([])&nbsp;&nbsp;= EQ<br>raw_compare (_:_) ([])&nbsp;&nbsp;= GT<br>raw_compare (_:x) (_:y) = raw_compare x y<br><br><br>instance Num LazyNatural where<br>&nbsp;&nbsp;(LN x) + (LN y) = LN (x ++ y)<br>&nbsp;&nbsp;(LN x) - (LN y) = LN (raw_minus x y)
<br>&nbsp;&nbsp;(LN x) * (LN y) = LN (concatMap (const x) y)<br>&nbsp;&nbsp;negate _ = error &quot;negate is not defined for LazyNatural&quot;<br>&nbsp;&nbsp;abs = id<br>&nbsp;&nbsp;signum (LN []) = LN []<br>&nbsp;&nbsp;signum (LN _)&nbsp;&nbsp;= LN [()]<br>&nbsp;&nbsp;fromInteger = LN . flip genericReplicate ()
<br><br>raw_minus (_:a) (_:b) = raw_minus a b<br>raw_minus (a)&nbsp;&nbsp; ([])&nbsp;&nbsp;= a<br>raw_minus _&nbsp;&nbsp;&nbsp;&nbsp; _&nbsp;&nbsp;&nbsp;&nbsp; = error &quot;negative result from subtraction&quot;<br><br>_______________________________________________<br>Haskell-Cafe mailing list
<br><a href="mailto:Haskell-Cafe@haskell.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Haskell-Cafe@haskell.org</a><br><a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br></blockquote></div><br>
</span></div></blockquote></div><br>