
On Tue, 13 Mar 2007 10:17:05 +0000
"Neil Mitchell"
Hi
-- 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? Gen