0

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
  • 1
    If you are "quite new to Haskell" and you "won't be able to do anything complicated" maybe writing a DPLL SAT solver is not the most appropriate choice for a first exercise. By all means, give it a try, but it could be helpful to get familiar with the language solving some more basic task, at first. Commented Feb 13, 2016 at 23:14

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Is this really correct? I don't see how your code would let the last 2 ifs to run?
@karambit I assumed that you have functions like find_pure_symbol and find_unit_symbol that return a tuple (p, value). The pattern guard clause with the <- applies the function, and the following condition (separated with a comma) is your if. I also assumed the existence of the functions nonnull, rest and first

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.