函数返回"无解"而不是"无"

dan*_*tin 9 functional-programming logic-programming curry maybe

我有一个表示谓词逻辑公式的标准数据类型.表示析出的自然演绎消除规则的函数可能如下所示:

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
Run Code Online (Sandbox Code Playgroud)

在统一失败时,该函数不返回Nothing,而是返回以下解决方案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.
Run Code Online (Sandbox Code Playgroud)

我错过了什么,为什么在统一失败时不el评价Nothing

max*_*kin 1

看来这不是使用方程约束的最佳方法。当a =:= b失败时,完整功能子句也会失败。
例如:

xx x = if (x =:= 5) == success then 1 else x
xx x = 3
Run Code Online (Sandbox Code Playgroud)

计算xx 7结果为3(not 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
Run Code Online (Sandbox Code Playgroud)