Skip to content

Instantly share code, notes, and snippets.

@sgrove

sgrove/build.sh Secret

Created February 1, 2016 20:16
Show Gist options
  • Save sgrove/7dcafd3d1458f5e7c907 to your computer and use it in GitHub Desktop.
Save sgrove/7dcafd3d1458f5e7c907 to your computer and use it in GitHub Desktop.
$ atdgen -t src/hn_item.atd && atdgen -j src/hn_item.atd && make clean && make && echo "Starting up..." && ./odaba.native
ocaml setup.ml -clean
ocaml setup.ml -build
ocamlfind ocamlopt unix.cmxa -I /usr/local/lib/ocaml/ocamlbuild /usr/local/lib/ocaml/ocamlbuild/ocamlbuildlib.cmxa -linkpkg myocamlbuild.ml /usr/local/lib/ocaml/ocamlbuild/ocamlbuild.cmx -o myocamlbuild
/Users/s/.opam/system/bin/ocamlfind ocamldep -package yojson -package threads -package opium -package irmin.unix -package irmin -package core -package cohttp -package biniou -package atdgen -package atd -modules src/odaba.ml > src/odaba.ml.depends
/Users/s/.opam/system/bin/ocamlfind ocamlc -c -w +9+27+32 -warn-error +a -g -annot -bin-annot -thread -package yojson -package threads -package opium -package irmin.unix -package irmin -package core -package cohttp -package biniou -package atdgen -package atd -I src -o src/odaba.cmo src/odaba.ml
+ /Users/s/.opam/system/bin/ocamlfind ocamlc -c -w +9+27+32 -warn-error +a -g -annot -bin-annot -thread -package yojson -package threads -package opium -package irmin.unix -package irmin -package core -package cohttp -package biniou -package atdgen -package atd -I src -o src/odaba.cmo src/odaba.ml
File "src/odaba.ml", line 26, characters 35-42:
Error: This expression has type tx_datom list
but an expression was expected of type datom
Command exited with code 2.
E: Failure("Command ''/usr/local/bin/ocamlbuild' src/odaba.native -use-ocamlfind -cflags '-w +9+27+32 -warn-error +a' -tag debug' terminated with error code 10")
make: *** [build] Error 1
type db_value =
| S of string
| I of int
type tx_datom =
{
e : int;
a : string;
v : db_value;
}
type datom =
{
e : int;
a : string;
v : db_value;
t : int;
}
(* Goal is to take a list of tx_datom (which don't have a t
timestamp), convert them to a datom, and add them to the db *)
let transact : datom list -> tx_datom list -> datom list =
fun db txn ->
let new_datoms = List.map (fun (txn_dtm : tx_datom list) ->
{
e = txn_dtm.e;
a = txn_dtm.a;
v = txn_dtm.v;
t = 0;
}) txn
in
List.append db new_datoms
let (db : datom list) = []
let db' =
transact db
[{e = 1;
a = "age";
v = I 31}
; {e = 1;
a = "first_name";
v = S "Sean"}
; {e = 1;
a = "last_name";
v = S "Grove"}
; {e = 1;
a = "color";
v = S "Blue";}]
let db'' =
transact db'
[{e = 1;
a = "language";
v = S "OCaml";}
; {e = 2;
a = "first_name";
v = S "Daniel";}
; {e = 2;
a = "last_name";
v = S "Woelfel";}
; {e = 2;
a = "color";
v = S "Red";}
; {e = 2;
a = "language";
v = S "Clojure";}]
let entity db eid =
let table = Core.Std.String.Table.create () ~size:4 in
List.iter (fun dtm ->
if dtm.e = eid then
Core.Std.Hashtbl.set table ~key:dtm.a ~data:dtm) db;
table
exception Key_not_found of string
let sf key ent =
match Core.Std.Hashtbl.find ent key with
| Some {v = S x; _} -> x
| Some {v = I x; _} -> string_of_int x
| None -> raise (Key_not_found "Runtime crash!")
let language ent = sf "language" ent
let name ent = sf "first_name" ent
let () =
let daniel = entity db'' 2 in
let sean = entity db'' 1 in
print_endline ((name sean) ^ " dabbles in " ^ (language sean));
print_endline ((name daniel) ^ " dabbles in " ^ (language daniel))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment