簡體   English   中英

Haskell 中的 `>||<` 運算符有什么作用?

[英]What does the `>||<` operator do in Haskell?

有誰知道'>||<'在第 7 行以下的 Haskell 代碼段中做了什么? (DPLL 算法)

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

在 haskell 中,如果函數用括號括起來,則可以用符號命名。 例如

(+-+) :: Num a => a -> a -> a -> a
(+-+) x y z = (x+y) - z

它可以用於:

(+-+) 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

這里, doSome function 只能在fun1 scope 中調用,取兩個數相加。 在您的示例中:

dpll e v
  where
  units = ...
  unitLit =  ...
  lit = ...
  propagate n e = ...
  (>||<) x y = if x /= [] then x else y

您的函數具有以下類型:

(>||<) :: Eq a => [a] -> [a] -> [a]

(>||<) dpll scope 中定義的dpll ,如果第一個列表不為空,則返回第一個列表,如果第一個列表為空,則返回第二個列表。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM