mardi 7 mai 2019

Is there a multiple-condition if in Haskell?

I was trying to nest guards which check for more than two conditions like so:

f :: Int -> Int
f i
   | bool1
       | bool2 = a
       | bool3 = a2
       | otherwise = a3
   | bool4
       | bool5 = a4
       | bool6 = a5
       | bool7 = a6
   | bool8
...
   | otherwise = an



which gives me a parse error. Is the proper way to do this
to flatten the guards with && or
to implement a function like so:

multiIf :: [Bool] -> [a] -> a
multiIf (x:xs) (l:ls) = if x then l else multiIf xs ls
multiIf _ _ = undefined


Or is there another method?

Aucun commentaire:

Enregistrer un commentaire