50 lines
1.7 KiB
Haskell
50 lines
1.7 KiB
Haskell
module Main where
|
|
import Database
|
|
import Nondeterminism
|
|
import Classes
|
|
import Terms
|
|
import Binding
|
|
|
|
demoProgram :: Database
|
|
demoProgram = Database
|
|
{ clauses =
|
|
-- act(sam, 'goes to law school')
|
|
[ return $ Clause (Compound "act" [Compound "Sam" [], Compound "goes to law school" []]) []
|
|
, return $ Clause (Compound "vampire_behavior" [Compound "drinks blood" []]) []
|
|
, return $ Clause (Compound "vampire_behavior" [Compound "spits venom" []]) []
|
|
, do
|
|
-- act(Who, Action) :- is_vampire(Who), vampire_behavior(Action).
|
|
who <- newVar "Who"
|
|
action <- newVar "Action"
|
|
return $ Clause (Compound "act" [Var who, Var action])
|
|
[ Compound "is_vampire" [Var who]
|
|
, Compound "vampire_behavior" [Var action]
|
|
]
|
|
, do
|
|
-- is_vampire(Progeny) :- has_progenitor(Progenitor, Progeny), is_vampire(Progenitor)>
|
|
progenitor <- newVar "Progenitor"
|
|
progeny <- newVar "Progeny"
|
|
return $ Clause (Compound "is_vampire" [Var progeny])
|
|
[ Compound "has_progenitor" [Var progenitor, Var progeny]
|
|
, Compound "is_vampire" [Var progenitor]
|
|
]
|
|
, return $ Clause (Compound "is_vampire" [Compound "Nyeogmi" []]) []
|
|
, return $ Clause (Compound "has_progenitor" [Compound "Sam" [], Compound "Alex" []]) []
|
|
, return $ Clause (Compound "is_vampire" [Compound "Sam" []]) []
|
|
]
|
|
}
|
|
|
|
main :: IO ()
|
|
main = do
|
|
thread <- newThread runDemoProgram
|
|
_ <- takeAllRemainingSolutions thread
|
|
return ()
|
|
where
|
|
runDemoProgram :: PrologStream ()
|
|
runDemoProgram = do
|
|
who <- newVar "who"
|
|
what <- newVar "what"
|
|
let goal = Compound "act" [Var who, Var what]
|
|
goal' <- seekAndInstantiate goal demoProgram
|
|
liftIO $ putStrLn ("Got " ++ show goal')
|