Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: tower hanoi problem (Mike Meyer)
2. Re: tower hanoi problem (Roelof Wobben)
3. Re: tower hanoi problem (Mike Meyer)
4. Re: tower hanoi problem (Roelof Wobben)
----------------------------------------------------------------------
Message: 1
Date: Wed, 18 Feb 2015 19:29:10 -0600
From: Mike Meyer <[email protected]>
To: [email protected], The Haskell-Beginners Mailing List -
Discussion of primarily beginner-level topics related to Haskell
<[email protected]>
Subject: Re: [Haskell-beginners] tower hanoi problem
Message-ID:
<CAD=7u2cqoemwy_o4c+m26otft3wilrc3tx2rvig9tygbvvg...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Wed, Feb 18, 2015 at 7:16 PM, Dudley Brooks <[email protected]>
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-0001.html>
------------------------------
Message: 2
Date: Thu, 19 Feb 2015 08:11:00 +0100
From: Roelof Wobben <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] tower hanoi problem
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150219/6307d0da/attachment-0001.html>
------------------------------
Message: 3
Date: Thu, 19 Feb 2015 01:25:41 -0600
From: Mike Meyer <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] tower hanoi problem
Message-ID:
<CAD=7u2bl9oj5xkzzb2uhdrbqvfrv+wm4wdk-wvjnfotd+1e...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Thu, Feb 19, 2015 at 1:11 AM, Roelof Wobben <[email protected]> wrote:
> I think I found the answer by some trail and error,
>
> hanoi 1 start _ end = [ (start, end)]
> hanoi n start temp end = hanoi (n-1) start end temp ++ [(start, end)] ++
> hanoi (n-1) temp start end
>
> main = print $ hanoi 3 'a' 'b' 'c'
>
I mentioned earlier that using "hanoi 1 start temp end" instead of
"[(start, end)]" made things read a bit better to me. I figured out why. It
isolates the final representation of a "move" to the base case only. So if
you make that change, you could then write your base case as:
hanoi 1 start _ end = "move 1 disk from " ++ start ++ " to " ++ end ++
".\n"
and the other case still works correctly if you used the "hanoi 1" version.
You'll want to change "print" to "putStr" in main, but it will now print
the list of moves in English instead of Haskell.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150219/237b0121/attachment-0001.html>
------------------------------
Message: 4
Date: Thu, 19 Feb 2015 08:35:03 +0100
From: Roelof Wobben <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] tower hanoi problem
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150219/a7f93fdc/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 80, Issue 49
*****************************************