Function Returns "No Solution" Instead Of "Nothing"
Asked Answered
B

1

9

I have a standard datatype representing formulae of predicate logic. A function representing a natural deduction elimination rule for disjunction might look like:

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

Instead of evaluating to Nothing when unification fails, the function returns no solutions in 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.

What am I missing, and why doesn't el evaluate to Nothing when unification fails?

Blister answered 30/9, 2011 at 13:55 Comment(3)
The language I'm using is Curry, a functional-logic programming langauge (see tags).Blister
oh - I'm sorry .... ignorance can be quite embarassing ....Pantin
As you probably know, "curry" is also a term that has meaning in other languages (like Haskell, obviously) so maybe you should add some content to the Stack Overflow wiki page for the curry tag.Inhumane
B
1

It seems that this is not the best way to use equational constraints. When a =:= b fails then complete function clause fails also.
E.g.:

xx x = if (x =:= 5) == success then 1 else x
xx x = 3

Evaluating xx 7 results in 3 (not 7) because 7 =:= 5 completely terminates first clause of the xx function.

I think the code should look like this:

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
Bellebelleek answered 3/12, 2011 at 10:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.