[Haskell-beginners] Conditionals where more than one case is true

Francesco Ariis fa-ml at ariis.it
Mon Apr 17 10:54:12 UTC 2017


On Mon, Apr 17, 2017 at 11:26:07AM +0100, PATRICK BROWNE wrote:
> I can apreciate that the program works when the first guard condition is
> met (faster Bob Joe).
> I am not sure why it fails on the second case (faster Bob Joe)

Your `fact` function is the one that is partial

    fact Buffalo Bob = True
    fact Pig Joe     = True
    fact Slug Steve  = True
    -- what if all those patterns fail?

You should add a line to handle "every other case", like

    fact Buffalo Bob = True
    fact Pig Joe     = True
    fact Slug Steve  = True
    fact _    _      = False

Does that help?


More information about the Beginners mailing list