Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type Entity = Entity of string
- type Relationship = Relationship of string
- let entity name = Entity(name)
- let relationship name = Relationship(name)
- let __ = entity("__")
- let facts = ref []
- let fact (rel:Relationship) (xs:Entity list) =
- facts := (rel,xs) :: !facts
- let question (Relationship(rel)) (clause:Entity list) =
- let find clause clause' =
- let xs = List.zip clause clause'
- if xs |> List.forall (fun (a,b) -> a = __ || a = b)
- then xs |> List.tryPick (fun (a,b) -> if a = __ then Some b else None)
- else None
- [for (Relationship(rel'),clause') in !facts do
- if rel = rel' then
- match find clause clause' with
- | Some(answer) -> yield answer
- | None -> ()
- ]
- let sally = entity "sally"
- let harry = entity "harry"
- let likes = relationship "likes"
- fact likes [harry;sally]
- question likes [harry;__]
- // val it : Entity list = [Entity "sally"]
- question likes [__;sally]
- // val it : Entity list = [Entity "harry"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement