Permalink
Browse files

match added

  • Loading branch information...
1 parent 58c6259 commit 97eff83606a39a752841b008200f9785d33c6ccf @doaitse doaitse committed May 30, 2011
Showing with 9 additions and 0 deletions.
  1. +9 −0 src/Language/Prolog/NanoProlog/NanoProlog.hs
@@ -21,6 +21,7 @@ module Language.Prolog.NanoProlog.NanoProlog (
, solve
, startParse
, unify
+ , matches
) where
import Data.ListLike.Base (ListLike)
@@ -82,6 +83,14 @@ instance Subst Term where
instance Subst Rule where
subst env (c :<-: cs) = subst env c :<-: subst env cs
+matches :: (Term, Term) -> Maybe Env -> Maybe Env
+matches _ Nothing = Nothing
+matches (t, u) env@(Just m) = match(subst m t) u
+ where match (Var x) y = Just (M.insert x y m)
+ match (Fun x xs) (Fun y ys)
+ | x == y && length xs == length ys = foldr matches env (zip xs ys)
+ match _ _ = Nothing
+
unify :: (Term, Term) -> Maybe Env -> Maybe Env
unify _ Nothing = Nothing
unify (t, u) env@(Just m) = uni (subst m t) (subst m u)

0 comments on commit 97eff83

Please sign in to comment.