samedi 30 avril 2016

Haskell and multiple conditions

If I have multiple conditions that are only slightly different, what is the best way to write a function (considering and inability to nest guards) of the form:

f | a && b && c  = 1
  | a && b && d  = 2
  | a && b && e  = 3
  | a && g && e  = 4

etc

Imagine there are more a lot more conditions. Ideally I would like to write a nested if that would check for a then b then something else, but I have been told that this not possible in Haskell.

Also, in the example. If the first line returns falls, are the conditions a and b checked again if they not defined in a where clause?

Aucun commentaire:

Enregistrer un commentaire