[Haskell-cafe] recursion problem part 2

Brandon Allbery allbery.b at gmail.com
Fri Feb 6 15:24:16 UTC 2015


On Fri, Feb 6, 2015 at 10:18 AM, Roelof Wobben <r.wobben at home.nl> wrote:

> Can someone give me a tip how to solve this
> I have asked this on the beginners ML but the only answer I get was
> someone who was using some if -then statement and I think I can be solved
> without.
>

You need to distinguish three "zero" cases:

- the value is itself zero
- leading zero (i.e. you hit the end of available digits)
- interior zero

The middle one is your end case --- but this will give you no output if the
value you put in initially is zero, since you're already at the end case.
So you need to treat an initial value of 0 specially somehow to get output
for it. So, either an explicit conditional or a setup where the public
function handles an explicit zero and otherwise defers to what you have,
which becomes an internal/hidden function (via where or let).

-- 
brandon s allbery kf8nh                               sine nomine associates
allbery.b at gmail.com                                  ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20150206/dd90c0f4/attachment.html>


More information about the Haskell-Cafe mailing list