simplify uni of consts

This commit is contained in:
Mirek Kratochvil 2023-01-14 23:12:25 +01:00
parent 80cf4b03a4
commit d9f5bcc0f9

View file

@ -162,8 +162,6 @@ proveStep = St.get >>= go
FreeRef gr -> setHeap hr (HeapRef gr) FreeRef gr -> setHeap hr (HeapRef gr)
BoundRef addr _ -> setHeap hr (HeapRef addr) BoundRef addr _ -> setHeap hr (HeapRef addr)
_ -> ifail "dangling goal ref (from head ref)" _ -> ifail "dangling goal ref (from head ref)"
BoundRef _ atom@(Atom _) -> unify atom g
BoundRef _ number@(Number _) -> unify number g
BoundRef addr struct@(Struct Id {arity = arity}) -> BoundRef addr struct@(Struct Id {arity = arity}) ->
c c
i i
@ -175,13 +173,12 @@ proveStep = St.get >>= go
, gol = U g : gs , gol = U g : gs
} }
} }
BoundRef _ x -> unify x g
_ -> ifail "dangling head ref" _ -> ifail "dangling head ref"
unify h (HeapRef gr') = unify h (HeapRef gr') =
case deref gr' of case deref gr' of
FreeRef gr -> FreeRef gr ->
case h of case h of
atom@(Atom _) -> setHeap gr atom
number@(Number _) -> setHeap gr number
s@(Struct _) -> s@(Struct _) ->
withNewHeapStruct withNewHeapStruct
gr gr
@ -194,7 +191,7 @@ proveStep = St.get >>= go
cur cur
{hed = hs, gol = map U ngs ++ gs, heap = nheap} {hed = hs, gol = map U ngs ++ gs, heap = nheap}
}) })
BoundRef _ atom@(Atom b) -> unify h atom x -> setHeap gr x
BoundRef addr struct@(Struct Id {arity = arity}) -> BoundRef addr struct@(Struct Id {arity = arity}) ->
c c
i i
@ -206,6 +203,7 @@ proveStep = St.get >>= go
[U (HeapRef $ addr + i) | i <- [1 .. arity]] ++ gs [U (HeapRef $ addr + i) | i <- [1 .. arity]] ++ gs
} }
} }
BoundRef _ x -> unify h x
_ -> ifail "dangling goal ref" _ -> ifail "dangling goal ref"
unify _ _ = backtrack unify _ _ = backtrack
{- Resolution -} {- Resolution -}