module Database where import Nondeterminism import Terms import Control.Applicative import Binding import Control.Monad data Clause = Clause Term [Term] data Database = Database { clauses :: [PrologStream Clause] } seekAndInstantiate :: Term -> Database -> PrologStream Term seekAndInstantiate goal db = do seek goal db instantiate goal seek :: Term -> Database -> PrologStream () seek goal db = do foldr (<|>) empty (map doClause (clauses db)) where doClause clause = do Clause chead body <- clause unify goal chead forM_ body $ \newGoal -> seek newGoal db