haskell - `>||<` 运算符在 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
解决方案
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.
推荐阅读
- java - 使用 java 调用远程系统 LPEX 编辑器
- sql - 使用 SQL 查找/标记重复值
- sap - 如何在 HANA 数据库中获取无效过程和函数的列表?
- python-3.x - 我可以根据字典的键创建输出吗?
- mongodb - Mongodb 获取延迟的间歇性峰值
- javascript - 如何在常用函数中存储控制器全局变量数据
- facebook - facebook 在使用 oauth2 时抛出“尝试检索 OAuth 2.0 访问令牌响应时发生错误”
- javascript - 编辑按钮工具提示颜色 Prime React
- flutter - Flutter PWA 未显示“添加到主屏幕”选项
- reactjs - React 中的 OnClick 事件在子组件中不起作用