Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Functional programming 函数返回";“没有解决办法”;而不是",;“什么都没有”;_Functional Programming_Logic Programming_Maybe_Curry - Fatal编程技术网

Functional programming 函数返回";“没有解决办法”;而不是",;“什么都没有”;

Functional programming 函数返回";“没有解决办法”;而不是",;“什么都没有”;,functional-programming,logic-programming,maybe,curry,Functional Programming,Logic Programming,Maybe,Curry,我有一个表示谓词逻辑公式的标准数据类型。表示析取的自然推断排除规则的函数可能如下所示: d_el p q = if p =: (Dis r s) && q =: (Neg r) then Just s else if q =: (Dis r s) && p =: (Neg r) then Just s else Nothing where r,s free x =: y = (x =:= y) == success 当统一失败时,该函数不返回

我有一个表示谓词逻辑公式的标准数据类型。表示析取的自然推断排除规则的函数可能如下所示:

d_el p q =
  if p =: (Dis r s) && q =: (Neg r) then Just s else
  if q =: (Dis r s) && p =: (Neg r) then Just s else
     Nothing where r,s free

x =: y = (x =:= y) == success
当统一失败时,该函数不返回任何结果,而是在
PACKS
中不返回任何解决方案:

logic> d_el (Dis Bot Top) (Not Bot)
Result: Just Top
More Solutions? [Y(es)/n(o)/a(ll)] n
logic> d_el (Dis Bot Top) (Not Top)
No more solutions.

我遗漏了什么,为什么当统一失败时,
el
不计算为
Nothing
。当
a=:=b
失败时,complete function子句也会失败。
例如:

计算
xx 7
会导致
3
(而不是
7
),因为
7=:=5
完全终止
xx
函数的第一个子句

我认为代码应该是这样的:

d_el p q = case (p,q) of
   (Dis a s, Neg b) -> if a == b then Just s else Nothing
   (Neg a, Dis b s) -> if a == b then Just s else Nothing
   _ -> Nothing

我使用的语言是Curry,一种函数逻辑编程语言(见标签)。。。。无知可能会让人尴尬……正如你可能知道的,“咖喱”这个词在其他语言中也有意义(很明显,像哈斯凯尔语),所以也许你应该这样做。
d_el p q = case (p,q) of
   (Dis a s, Neg b) -> if a == b then Just s else Nothing
   (Neg a, Dis b s) -> if a == b then Just s else Nothing
   _ -> Nothing