Skip to content

Commit

Permalink
Merge pull request #13 from StrykerKKD/split_up
Browse files Browse the repository at this point in the history
Spliting up and refactoring examples
  • Loading branch information
StrykerKKD authored Feb 8, 2020
2 parents d5cee01 + c155f9b commit b7415ef
Show file tree
Hide file tree
Showing 9 changed files with 269 additions and 309 deletions.
4 changes: 2 additions & 2 deletions bin/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(executables
(names example knowledge_base)
(public_names example knowledge_base)
(names example friends parents lovers map_coloring murder_mystery)
(public_names example friends parents lovers map_coloring murder_mystery)
(libraries logical base))
20 changes: 5 additions & 15 deletions bin/example.ml
Original file line number Diff line number Diff line change
@@ -1,36 +1,26 @@
open Logical

let print_state_stream title state_stream =
print_endline title;
let state_list = Base.Sequence.to_list state_stream in
Base.List.iter state_list ~f:(fun element ->
match element with
| Some value -> State.to_string value |> print_endline
| None -> ()
);
print_newline ()

let equal_result = Goal.equal (Value.var "a") (Value.int 1) State.empty
let () = print_state_stream "equal_result" equal_result
let () = Util.print_state_stream "equal_result" equal_result

let either_result = Goal.either
(Goal.equal (Value.var "a") (Value.int 1))
(Goal.equal (Value.var "b") (Value.int 2))
State.empty
let () = print_state_stream "either_result" either_result
let () = Util.print_state_stream "either_result" either_result

let either_result_multi = Goal.either_multi
[Goal.equal (Value.var "a") (Value.int 1); Goal.equal (Value.var "b") (Value.int 2);
Goal.equal (Value.var "b") (Value.int 3);]
State.empty
let () = print_state_stream "either_result_multi" either_result_multi
let () = Util.print_state_stream "either_result_multi" either_result_multi

let both_result = Goal.both
(Goal.equal (Value.var "a") (Value.int 1))
(Goal.equal (Value.var "b") (Value.int 2))
State.empty
let () = print_state_stream "both_result" both_result
let () = Util.print_state_stream "both_result" both_result

let my_set = Base.Set.of_list (module Type) [Value.int 1; Value.int 2; Value.int 3]
let in_set_result = Goal.in_set (Value.var "a") my_set State.empty
let () = print_state_stream "in_set_result" in_set_result
let () = Util.print_state_stream "in_set_result" in_set_result
46 changes: 46 additions & 0 deletions bin/friends.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
open Logical

let first_friend_var = "first_friend_var"
let second_friend_var = "second_friend_var"

let friend first_friend second_friend =
Goal.both
(Goal.equal (Value.var first_friend_var) (Value.str first_friend))
(Goal.equal (Value.var second_friend_var) (Value.str second_friend))

let friend_refl first_friend second_friend =
Goal.either
(friend first_friend second_friend)
(friend second_friend first_friend)

let friend_db =
Goal.either_multi [
friend "john" "julia";
friend "john" "jack";
friend "julia" "sam";
friend "julia" "molly";
]

let friend_refl_db =
Goal.either_multi [
friend_refl "john" "julia";
friend_refl "john" "jack";
friend_refl "julia" "sam";
friend_refl "julia" "molly";
]

let friend_refl_querying first_friend second_friend =
Goal.either
(fun state -> friend_db (State.create_exn [first_friend_var,first_friend; second_friend_var,second_friend]))
(fun state -> friend_db (State.create_exn [first_friend_var,second_friend; second_friend_var,first_friend]))
State.empty

let friend_querying first_friend second_friend =
friend_refl_db (State.create_exn [first_friend_var, first_friend; second_friend_var, second_friend])

let friend_normal_query_state_stream = friend_querying (Value.str "julia") (Value.str "john")
let _ = Util.print_state_stream "Friends: using normal query on refl DB" friend_normal_query_state_stream


let friend_refl_query_state_stream = friend_refl_querying (Value.str "julia") (Value.str "john")
let _ = Util.print_state_stream "Friends: using refl query on simple DB" friend_refl_query_state_stream
292 changes: 0 additions & 292 deletions bin/knowledge_base.ml

This file was deleted.

Loading

0 comments on commit b7415ef

Please sign in to comment.