Reputation: 9
Does anyone know what '>||<'
does in the Haskell piece of code that's below-7th line? (the DPLL algorithm)
dpll :: Eq a => CNF a -> Valuation a -> Valuation a
dpll e v
| e == [] = v
| elem [] e = []
| units /= [] = dpll (propagate unitLit e) (v ++ [unitLit])
| otherwise = dpll (propagate lit e) (v ++ [lit])
>||< dpll (propagate (neg lit) e) (v ++ [(neg lit)])
where
units = filter (\x -> (length x) == 1) e
unitLit = head $ head units
lit = head $ head e
propagate n e = map (\\ [neg n]) $ filter (notElem n) e
(>||<) x y = if x /= [] then x else y
Upvotes: 0
Views: 92
Reputation: 16224
In haskell, functions can be named with symbols if they are closed by parentheses. For example
(+-+) :: Num a => a -> a -> a -> a
(+-+) x y z = (x+y) - z
it can be used:
(+-+) 3 4 2
=> 5
When you use a where
clause, you are telling Haskell to create a function with the scope of the function where is called, so, for example:
fun1 r m = doSome r m
where
doSome r1 m1 = r1 + m1
here, doSome
function can be called only in fun1
scope, and it takes two numbers and sum them together. In your example:
dpll e v
where
units = ...
unitLit = ...
lit = ...
propagate n e = ...
(>||<) x y = if x /= [] then x else y
your functions has the type:
(>||<) :: Eq a => [a] -> [a] -> [a]
(>||<)
its a function defined in dpll
scope, and it returns the first list if the first list is not empty, if the first list is empty, it return the second list.
Upvotes: 4