Haskell - multiple IF statements

1.2k views Asked by At

enter image description here

I would like to implement the DPLL algorithm above in Haskell. But the problem is I don't know how to get multiple if statements to run. So I was thinking, you can pattern match for the first 2 if statements. But you can't do it for the third and fourth? Because both of them must run and the return statement must run too.

How do I make multiple if statements like the above in Haskell? Also I'm quite new to Haskell so I won't be able to do anything 'complicated'.

1

There are 1 answers

2
Ingo On BEST ANSWER

Use pattern guards. For example

dpll clauses symbols modell
  | "all clauses true" = true
  | "some clauses false" = false
  | (p,value) <- find_pure_symbol symbols clauses model,
    nonnull p = dpll clauses ...
  | (p,value) <- find_unit_clause clauses model,
    nonnull p = dpll clauses ...
  | p <- first symbols, r <- rest symbols =
                dpll clauses ... || dpll clauses ....

(It looks like not all clauses true does not mean some clauses false, otherwise you could never reach the 3rd and following cases.)

The challenge is then to formulate the conditions, in the example I have marked them with " around them, but they are normal haskell expressions of type Bool.