[Haskell-beginners] Help on first program

John M. Dlugosz ngnr63q02 at sneakemail.com
Fri Mar 28 23:49:07 UTC 2014


On 3/28/2014 6:14 PM, Brandon Allbery wrote:
> On Fri, Mar 28, 2014 at 7:10 PM, John M. Dlugosz <ngnr63q02 at sneakemail.com
> <mailto:ngnr63q02 at sneakemail.com>> wrote:
>
>     Each recursive call is either 1 or (n-1) so it should count down 5,4,3,2,1 and stop
>     the recursion.
>
>     What am I missing?
>
>
> It doesn't magically stop at 0; Integer (inferred type) is signed. Moreover, even if it
> were not signed, it would wrap around (or possibly throw an exception on some CPUs, but
> not on Intel). You need to include a check for 0 to stop the recursion.
>
I don't get it.  When n == 1 it should match the second form, and that is not recursive.

Ah, they are matched in order!
(Yes, it works if I reverse the clauses)

Hmm, so it figures out the type from all of them?  I worried about putting specialized 
ones first because there is far less information.




More information about the Beginners mailing list