[Haskell-cafe] Re: Maybe and partial functions
genneth at gmail.com
Tue Mar 13 07:22:54 EDT 2007
On Tue, 13 Mar 2007 10:17:05 +0000
"Neil Mitchell" <ndmitchell at gmail.com> wrote:
> > -- There are no pattern-matching failures here.
> > -- The totality is harder to see: all digits are roughly of the
> > same range, -- but each recursive call increments base. Eventually,
> > base becomes bigger -- than d+9 and so the first alternative will
> > be selected, which is in the -- WHNF and so recursion terminates.
> > carryPropagate base (C d ds)
> > | carryguess == (d+9) `div` base
> > = C carryguess (C (remainder+nextcarry) fraction)
> > | otherwise
> > = (C (dCorrected `div` base) (C (dCorrected `mod` base)
> > fraction)) where carryguess = d `div` base
> > remainder = d `mod` base
> > C nextcarry fraction = carryPropagate (base+1) ds
> > dCorrected = d + nextcarry
> > e = map (show.head) $
> > iterate (carryPropagate 2 . map (10*) . tail) $
> > C 2 (rept 1)
> > en n = "2." ++ concat (take n (tail e))
> You still have div and mod, which are partial functions.
Surely we can assume them total given that base is never zero?
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 189 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20070313/253e7e09/signature.bin
More information about the Haskell-Cafe