[Haskell-cafe] Haskell function help

Carsten Schultz carsten at codimi.de
Tue Feb 1 20:26:16 CET 2011

Am 01.02.11 14:05, schrieb Houdini:
> that is really.....complicated...hmm

Maybe you find

assign :: (Atom,Bool)->Formula->Formula

assign _ [] = []
assign (a,b) (c:cs)
       | (b,a) `elem` c = cs'
       | otherwise = filter ((/= a).snd) c : cs'
       where cs' = assign (a,b) cs

easier to read.  With

example :: Formula
example = [[p,q,r],[n p,q,n r],[p,n q]]
    where p = l "P"
          q = l "Q"
          r = l "R"
          l a = (True, a)
          n (b,a) = (not b, a)

we get

*Algorithm> example
*Algorithm> assign ("P", True) example
*Algorithm> assign ("P", False) example

But note that we also get

*Algorithm> assign ("P", False)

So this is not reduced to [[]].

hth C.

More information about the Haskell-Cafe mailing list