[Haskell-beginners] tower hanoi problem

Mike Meyer mwm at mired.org
Thu Feb 19 01:29:10 UTC 2015


On Wed, Feb 18, 2015 at 7:16 PM, Dudley Brooks <dbrooks at runforyourlife.org>
wrote:

>  Hmm.  Well, I'd say that that's a feature of, specifically, Haskell's
> pattern-matching strategy and list-description syntax, rather than of
> recursion in general or the structure of this particular problem.  In other
> languages with recursion you might have no choice except to start with the
> base case, even for this problem, or else you'd get the same kind of error
> you mention below (depending on the language).  I think it's good when
> you're *learning* recursion to always start with the base case(s).
>
> I disagree that this is a Haskell-specific feature. Any else-if like
structure will have this property, no matter what language it's in. That
Haskell provides a syntax as part of the function declaration is special,
but that doesn't let you avoid the else-if construct when the problem
requires it.

It may be my fondness for proof by induction, but I think doing the base
case first is a good idea for another reason. The code for the recursive
cases assumes that you can correctly handle all the "smaller" cases. If
that's wrong because some assumption about the base case turns out to be
false when you actually write it, then you have to rewrite the recursive
cases for the correct base case. So it's better to make sure your base case
is going to work before you start writing the code that's going to use it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150218/ba4c16aa/attachment.html>


More information about the Beginners mailing list