From 7c3198fee4de005290d5d8cd942c9921cd0b34d5 Mon Sep 17 00:00:00 2001 From: SowinskiBraeden Date: Thu, 19 Feb 2026 11:59:58 -0800 Subject: [PATCH] restructure + lecutre 07 --- {lab01 => labs/01}/expo.ml | 0 {lab01 => labs/01}/lab1.ml | 0 {lab02 => labs/02}/lab2.ml | 0 {lab03 => labs/03}/kvtree.ml | 0 {lab03 => labs/03}/part1.ml | 0 labs/04/_build/_digests | 5 + labs/04/_build/_log | 12 ++ labs/04/_build/records.cmx | Bin 0 -> 990 bytes labs/04/_build/records.ml | 143 ++++++++++++++++++ labs/04/_build/records.ml.depends | 1 + labs/04/_build/records.o | Bin 0 -> 26096 bytes {lab04 => labs/04}/data.txt | 0 {lab04 => labs/04}/data1.txt | 0 {lab04 => labs/04}/data2.txt | 0 {lab04 => labs/04}/records.ml | 0 {lab05 => labs/05}/kvtree/kvtree.ml | 6 +- {lab05 => labs/05}/kvtree/kvtree.mli | 0 {lab05 => labs/05}/kvtree/tests.ml | 0 {lecture01 => lectures/01}/notes.ml | 0 {lecture01 => lectures/01}/tinker.ml | 0 {lecture02 => lectures/02}/html/Length.html | 0 {lecture02 => lectures/02}/html/index.html | 0 .../02}/html/index_attributes.html | 0 .../02}/html/index_class_types.html | 0 .../02}/html/index_classes.html | 0 .../02}/html/index_exceptions.html | 0 .../02}/html/index_extensions.html | 0 .../02}/html/index_methods.html | 0 .../02}/html/index_module_types.html | 0 .../02}/html/index_modules.html | 0 .../02}/html/index_types.html | 0 .../02}/html/index_values.html | 0 {lecture02 => lectures/02}/html/style.css | 0 .../02}/html/type_Length.html | 0 {lecture02 => lectures/02}/lists.ml | 0 {lecture02 => lectures/02}/notes02.ml | 0 {lecture03 => lectures/03}/notes03.ml | 0 {lecture04 => lectures/04}/bstree.ml | 0 {lecture04 => lectures/04}/bstree.mli | 0 {lecture04 => lectures/04}/notes.ml | 0 lectures/05/_build/_digests | 25 +++ lectures/05/_build/_log | 12 ++ lectures/05/_build/cat.cmx | Bin 0 -> 218 bytes lectures/05/_build/cat.ml | 25 +++ lectures/05/_build/cat.ml.depends | 1 + lectures/05/_build/cat.o | Bin 0 -> 3224 bytes lectures/05/_build/echo.cmx | Bin 0 -> 489 bytes {lecture05 => lectures/05/_build}/echo.ml | 0 lectures/05/_build/echo.ml.depends | 1 + lectures/05/_build/echo.o | Bin 0 -> 3496 bytes lectures/05/_build/number_file_lines.cmx | Bin 0 -> 548 bytes .../05/_build}/number_file_lines.ml | 0 .../05/_build/number_file_lines.ml.depends | 1 + lectures/05/_build/number_file_lines.o | Bin 0 -> 5768 bytes lectures/05/_build/number_lines.cmx | Bin 0 -> 411 bytes .../05/_build}/number_lines.ml | 0 lectures/05/_build/number_lines.ml.depends | 1 + lectures/05/_build/number_lines.o | Bin 0 -> 3752 bytes lectures/05/_build/sum_integers.cmx | Bin 0 -> 477 bytes .../05/_build}/sum_integers.ml | 0 lectures/05/_build/sum_integers.ml.depends | 1 + lectures/05/_build/sum_integers.o | Bin 0 -> 5056 bytes {lecture05 => lectures/05}/cat.ml | 0 {lecture05 => lectures/05}/data.txt | 0 lectures/05/echo.ml | 6 + {lecture05 => lectures/05}/notes.ml | 1 - lectures/05/number_file_lines.ml | 16 ++ lectures/05/number_lines.ml | 9 ++ {lecture05 => lectures/05}/output | 0 {lecture05 => lectures/05}/ref.ml | 0 lectures/05/sum_integers.ml | 12 ++ lectures/06/_build/_digests | 3 + lectures/06/_build/_log | 8 + .../06/_build}/two_list_queue.ml | 0 lectures/06/_build/two_list_queue.ml.depends | 1 + {lecture06 => lectures/06}/bstree.ml | 0 {lecture06 => lectures/06}/bstree.mli | 0 {lecture06 => lectures/06}/bstree2.ml | 0 .../06}/functor/_build/_digests | 0 .../06}/functor/_build/_log | 0 .../06}/functor/_build/bstree.ml | 0 .../06}/functor/_build/bstree.ml.depends | 0 .../06}/functor/_build/bstree.mli | 0 .../06}/functor/_build/bstree.mli.depends | 0 {lecture06 => lectures/06}/functor/bstree.ml | 0 {lecture06 => lectures/06}/functor/bstree.mli | 0 {lecture06 => lectures/06}/notes.ml | 0 {lecture06 => lectures/06}/notes.txt | 0 {lecture06 => lectures/06}/queue.ml | 0 lectures/06/two_list_queue.ml | 42 +++++ lectures/07/bstree.ml | 2 + lectures/07/counter.ml | 7 + lectures/07/frequency.ml | 12 ++ lectures/07/leftist.ml | 46 ++++++ lectures/07/modules.ml | 47 ++++++ lectures/07/sieve.ml | 16 ++ 96 files changed, 458 insertions(+), 4 deletions(-) rename {lab01 => labs/01}/expo.ml (100%) rename {lab01 => labs/01}/lab1.ml (100%) rename {lab02 => labs/02}/lab2.ml (100%) rename {lab03 => labs/03}/kvtree.ml (100%) rename {lab03 => labs/03}/part1.ml (100%) create mode 100644 labs/04/_build/_digests create mode 100644 labs/04/_build/_log create mode 100644 labs/04/_build/records.cmx create mode 100644 labs/04/_build/records.ml create mode 100644 labs/04/_build/records.ml.depends create mode 100644 labs/04/_build/records.o rename {lab04 => labs/04}/data.txt (100%) rename {lab04 => labs/04}/data1.txt (100%) rename {lab04 => labs/04}/data2.txt (100%) rename {lab04 => labs/04}/records.ml (100%) rename {lab05 => labs/05}/kvtree/kvtree.ml (97%) rename {lab05 => labs/05}/kvtree/kvtree.mli (100%) rename {lab05 => labs/05}/kvtree/tests.ml (100%) rename {lecture01 => lectures/01}/notes.ml (100%) rename {lecture01 => lectures/01}/tinker.ml (100%) rename {lecture02 => lectures/02}/html/Length.html (100%) rename {lecture02 => lectures/02}/html/index.html (100%) rename {lecture02 => lectures/02}/html/index_attributes.html (100%) rename {lecture02 => lectures/02}/html/index_class_types.html (100%) rename {lecture02 => lectures/02}/html/index_classes.html (100%) rename {lecture02 => lectures/02}/html/index_exceptions.html (100%) rename {lecture02 => lectures/02}/html/index_extensions.html (100%) rename {lecture02 => lectures/02}/html/index_methods.html (100%) rename {lecture02 => lectures/02}/html/index_module_types.html (100%) rename {lecture02 => lectures/02}/html/index_modules.html (100%) rename {lecture02 => lectures/02}/html/index_types.html (100%) rename {lecture02 => lectures/02}/html/index_values.html (100%) rename {lecture02 => lectures/02}/html/style.css (100%) rename {lecture02 => lectures/02}/html/type_Length.html (100%) rename {lecture02 => lectures/02}/lists.ml (100%) rename {lecture02 => lectures/02}/notes02.ml (100%) rename {lecture03 => lectures/03}/notes03.ml (100%) rename {lecture04 => lectures/04}/bstree.ml (100%) rename {lecture04 => lectures/04}/bstree.mli (100%) rename {lecture04 => lectures/04}/notes.ml (100%) create mode 100644 lectures/05/_build/_digests create mode 100644 lectures/05/_build/_log create mode 100644 lectures/05/_build/cat.cmx create mode 100644 lectures/05/_build/cat.ml create mode 100644 lectures/05/_build/cat.ml.depends create mode 100644 lectures/05/_build/cat.o create mode 100644 lectures/05/_build/echo.cmx rename {lecture05 => lectures/05/_build}/echo.ml (100%) create mode 100644 lectures/05/_build/echo.ml.depends create mode 100644 lectures/05/_build/echo.o create mode 100644 lectures/05/_build/number_file_lines.cmx rename {lecture05 => lectures/05/_build}/number_file_lines.ml (100%) create mode 100644 lectures/05/_build/number_file_lines.ml.depends create mode 100644 lectures/05/_build/number_file_lines.o create mode 100644 lectures/05/_build/number_lines.cmx rename {lecture05 => lectures/05/_build}/number_lines.ml (100%) create mode 100644 lectures/05/_build/number_lines.ml.depends create mode 100644 lectures/05/_build/number_lines.o create mode 100644 lectures/05/_build/sum_integers.cmx rename {lecture05 => lectures/05/_build}/sum_integers.ml (100%) create mode 100644 lectures/05/_build/sum_integers.ml.depends create mode 100644 lectures/05/_build/sum_integers.o rename {lecture05 => lectures/05}/cat.ml (100%) rename {lecture05 => lectures/05}/data.txt (100%) create mode 100644 lectures/05/echo.ml rename {lecture05 => lectures/05}/notes.ml (99%) create mode 100644 lectures/05/number_file_lines.ml create mode 100644 lectures/05/number_lines.ml rename {lecture05 => lectures/05}/output (100%) rename {lecture05 => lectures/05}/ref.ml (100%) create mode 100644 lectures/05/sum_integers.ml create mode 100644 lectures/06/_build/_digests create mode 100644 lectures/06/_build/_log rename {lecture06 => lectures/06/_build}/two_list_queue.ml (100%) create mode 100644 lectures/06/_build/two_list_queue.ml.depends rename {lecture06 => lectures/06}/bstree.ml (100%) rename {lecture06 => lectures/06}/bstree.mli (100%) rename {lecture06 => lectures/06}/bstree2.ml (100%) rename {lecture06 => lectures/06}/functor/_build/_digests (100%) rename {lecture06 => lectures/06}/functor/_build/_log (100%) rename {lecture06 => lectures/06}/functor/_build/bstree.ml (100%) rename {lecture06 => lectures/06}/functor/_build/bstree.ml.depends (100%) rename {lecture06 => lectures/06}/functor/_build/bstree.mli (100%) rename {lecture06 => lectures/06}/functor/_build/bstree.mli.depends (100%) rename {lecture06 => lectures/06}/functor/bstree.ml (100%) rename {lecture06 => lectures/06}/functor/bstree.mli (100%) rename {lecture06 => lectures/06}/notes.ml (100%) rename {lecture06 => lectures/06}/notes.txt (100%) rename {lecture06 => lectures/06}/queue.ml (100%) create mode 100644 lectures/06/two_list_queue.ml create mode 100644 lectures/07/bstree.ml create mode 100644 lectures/07/counter.ml create mode 100644 lectures/07/frequency.ml create mode 100644 lectures/07/leftist.ml create mode 100644 lectures/07/modules.ml create mode 100644 lectures/07/sieve.ml diff --git a/lab01/expo.ml b/labs/01/expo.ml similarity index 100% rename from lab01/expo.ml rename to labs/01/expo.ml diff --git a/lab01/lab1.ml b/labs/01/lab1.ml similarity index 100% rename from lab01/lab1.ml rename to labs/01/lab1.ml diff --git a/lab02/lab2.ml b/labs/02/lab2.ml similarity index 100% rename from lab02/lab2.ml rename to labs/02/lab2.ml diff --git a/lab03/kvtree.ml b/labs/03/kvtree.ml similarity index 100% rename from lab03/kvtree.ml rename to labs/03/kvtree.ml diff --git a/lab03/part1.ml b/labs/03/part1.ml similarity index 100% rename from lab03/part1.ml rename to labs/03/part1.ml diff --git a/labs/04/_build/_digests b/labs/04/_build/_digests new file mode 100644 index 0000000..bc54875 --- /dev/null +++ b/labs/04/_build/_digests @@ -0,0 +1,5 @@ +"Rule: ocaml dependencies ml (%=records )": "\168\187\158\232\128I\157\015\216j\244\004\243\234\011\217" +"Rule: ocaml: ml & cmi -> cmx & o (%=records )": "5\144\205\021B\003\025\204\145\159\255\166t\136\140^" +"Resource: /home/flami/Projects/comp3958/lab04/records.ml": "\133\242qUUy2\188\b\134=\163c9\2142" +"Rule: ocaml: ml -> cmo & cmi (%=records )": "\026zi!\193g\255\238<\162\135s\021\142\001\012" +"Rule: ocaml: cmx* & o* -> native (%=records )": "C\176\141F\181\127\251\240\211V\156\t\167\208\129\177" diff --git a/labs/04/_build/_log b/labs/04/_build/_log new file mode 100644 index 0000000..4f9a364 --- /dev/null +++ b/labs/04/_build/_log @@ -0,0 +1,12 @@ +### Starting build. +# Target: /home/flami/.opam/default/bin/ocamlc.opt -config, tags: { } +/home/flami/.opam/default/bin/ocamlc.opt -config +# Target: records.ml.depends, tags: { extension:ml, file:records.ml, ocaml, ocamldep, quiet } +/home/flami/.opam/default/bin/ocamldep.opt -modules records.ml > records.ml.depends +# Target: records.cmo, tags: { byte, compile, extension:cmo, extension:ml, file:records.cmo, file:records.ml, implem, ocaml, quiet } +/home/flami/.opam/default/bin/ocamlc.opt -c -o records.cmo records.ml +# Target: records.cmx, tags: { compile, extension:cmx, extension:ml, file:records.cmx, file:records.ml, implem, native, ocaml, quiet } +/home/flami/.opam/default/bin/ocamlopt.opt -c -o records.cmx records.ml +# Target: records.native, tags: { dont_link_with, extension:native, file:records.native, link, native, ocaml, program, quiet } +/home/flami/.opam/default/bin/ocamlopt.opt records.cmx -o records.native +# Compilation successful. diff --git a/labs/04/_build/records.cmx b/labs/04/_build/records.cmx new file mode 100644 index 0000000000000000000000000000000000000000..8fcc2a8f5cc5d780c42382e6aad14c504c197e36 GIT binary patch literal 990 zcmZ=x%*`>hw6u&gFg9zMx@;c<1M@lt28I#_1}0tx2F7(93=H}V>OrZ=`9&$kEQ||S zm>d=?&)v|%cOD~l%>tmrCz z&%fe{&4XNyJ%9J?i9(i7Eu3H=D`WUTyPTc>!&A9ctF=CyL9!t@IWaG7f`Q(2%jrF< zHaoQ6X?E;7H}~0s1$rGdvyLUOA}MjrEXha(y7R(S zmm6zyZd{(2_l@O6U3Vpt5~tF%G>{U>sfLXiBn>6W->6S;!m4MawY98sr2F6sng1F z6d2kdGer3cGgb)vm_PNwl*#)Uc~p>`1r4G149^2kM-(fUI4$m2e)i)bB)`EzNGN8y zoZ(uj9CfubtKL^-00R;3a=RUd9q->=F!hfJJTlw8QPp9A^8zOb;V@w$I1wy(V4Dnd zHZ&>d6@Y?0z6g>q;*HEL9335iXu$(}WL3%exdn+usc?11Mg~q$b#}<=VCH1z6{i-J z#2Xu#z?5++BdaS(Ek;-hS8NHh+Xh)}aX!!_n8C)zMleO3ipZ+KCZZ`dgDEvdRtfY- zacaD=G2AvQWLdB|P$g!DFas=+l@z5Wro^XZ<^T;bgZmF97@*!mD1(P8O4t{b=EW!G hR literal 0 HcmV?d00001 diff --git a/labs/04/_build/records.ml b/labs/04/_build/records.ml new file mode 100644 index 0000000..5a7aa97 --- /dev/null +++ b/labs/04/_build/records.ml @@ -0,0 +1,143 @@ +(** [record] of a person with a first name, last name, and score *) +type record = {firstname: string; lastname: string; score: int};; + +(** [print_records r] takes a list of records [r] and prints + * each record neatly to the console *) +let rec print_records r = + match r with + | [] -> () + | x :: xs -> Printf.printf "%3d %s %s\n" x.score x.lastname x.firstname; print_records xs;; + +(** [compare_records r1 r2] compares records [r1] and [r2] based + * on score, then by lastname, then by firstname. + *) +let compare_records r1 r2 = + compare + (r2.score, r2.lastname, r2.firstname) + (r1.score, r1.lastname, r1.firstname);; + +(** [records_insert x l] inserts a record element [x] into + * list of records [l] + * Requires: [l] is in ascending order. *) +let rec records_insert x l = + match l with + | y :: ys when compare_records x y > 0 -> y :: records_insert x ys + | _ -> x :: l;; + +(**/**) +let test_records_insert () = + assert (records_insert + {firstname = "a"; lastname = "b"; score = 1} [] = + [{firstname = "a"; lastname = "b"; score = 1}] + ); + assert (records_insert + {firstname = "a"; lastname = "b"; score = 1} + [{firstname = "c"; lastname = "d"; score = 2}] = + [ + {firstname = "c"; lastname = "d"; score = 2}; + {firstname = "a"; lastname = "b"; score = 1} + ]); + assert (records_insert + {firstname = "e"; lastname = "f"; score = 2} + [ + {firstname = "c"; lastname = "d"; score = 3}; + {firstname = "a"; lastname = "b"; score = 1} + ] = + [ + {firstname = "c"; lastname = "d"; score = 3}; + {firstname = "e"; lastname = "f"; score = 2}; + {firstname = "a"; lastname = "b"; score = 1} + ]);; +(**/**) + +(** [records_insertion_sort l] sorts list of records [l] in ascending order *) +let rec sort_records l = + match l with + | [] -> [] + | x :: xs -> records_insert x (sort_records xs);; + +(**/**) +let test_sort_records () = + assert (sort_records [] = []); + assert (sort_records + [{firstname = "a"; lastname = "b"; score = 1}] = + [{firstname = "a"; lastname = "b"; score = 1}]); + + assert (sort_records [ + {firstname = "c"; lastname = "d"; score = 3}; + {firstname = "a"; lastname = "b"; score = 1}; + {firstname = "e"; lastname = "f"; score = 2}; + ] = [ + {firstname = "c"; lastname = "d"; score = 3}; + {firstname = "e"; lastname = "f"; score = 2}; + {firstname = "a"; lastname = "b"; score = 1}; + ]);; +(**/**) + +(** [parse l] takes in a line [l] and parses the line to extract + * firstname, lastname, and score, returning Some record if successful + * or None if the input line [l] contains bad data *) +let rec parse l = + try + Scanf.sscanf l " %s %s %s" (fun f l s -> + match int_of_string_opt s with + | Some v when v >= 0 && v <= 100 -> Some {firstname = f; lastname = l; score = v} + | _ -> None + ) + with + | Scanf.Scan_failure _ -> None;; + +(**/**) +let test_parse () = + assert (parse "" = None); + assert (parse "Bart simpson 5abc" = None); + assert (parse "Lisa simpson 130" = None); + assert (parse "Homer Simpson -5" = None); + assert (parse "Homer Simpson 5" = + Some {firstname = "Homer"; lastname = "Simpson"; score = 5}); + assert (parse "Homer Simpson 5 blah blah blah" = + Some {firstname = "Homer"; lastname = "Simpson"; score = 5});; +(**/**) + +(** [read_file acc ic] takes in an accumulator [acc] and an input channel [ic] + * and oterates over it input channel [ic] to parse each line and store the + * parsed result into the accumulator [acc] *) +let rec read_file acc ic = + try + match parse @@ input_line ic with + | None -> read_file acc ic + | Some v -> read_file (v :: acc) ic + with + | End_of_file -> close_in ic; acc;; + +(**/**) +let test_read_file () = + assert (read_file [] @@ open_in "data.txt" = [ + {firstname = "gary"; lastname = "chalmers"; score = 5}; + {firstname = "waylon"; lastname = "smithers"; score = 100}; + {firstname = "homer"; lastname = "simpson"; score = 25}; + ]); + assert (read_file [] @@ open_in "data1.txt" = [ + {firstname = "gary"; lastname = "chalmers"; score = 5}; + {firstname = "waylon"; lastname = "smithers"; score = 100}; + {firstname = "ned"; lastname = "flanders"; score = 12}; + {firstname = "homer"; lastname = "simpson"; score = 25}; + ]); + assert (read_file [] @@ open_in "data2.txt" = []);; +(**/**) + +(**/**) +let run_all_tests () = + test_parse(); + test_read_file(); + test_records_insert(); + test_sort_records();; +(**/**) + +(** main program entry from cli *) +let () = + if Array.length Sys.argv = 1 then + Printf.printf "%s: expects 1 file input.\nUsage: \"%s \"\n" Sys.argv.(0) Sys.argv.(0) + else + let ic = open_in Sys.argv.(1) in + print_records @@ sort_records @@ read_file [] ic;; diff --git a/labs/04/_build/records.ml.depends b/labs/04/_build/records.ml.depends new file mode 100644 index 0000000..b0ac031 --- /dev/null +++ b/labs/04/_build/records.ml.depends @@ -0,0 +1 @@ +records.ml: Array Printf Scanf Sys diff --git a/labs/04/_build/records.o b/labs/04/_build/records.o new file mode 100644 index 0000000000000000000000000000000000000000..371a671809e8bfb10c155e5cda45793ac8250f81 GIT binary patch literal 26096 zcmeI4e{|H-s58EmwXU&hLw$&gG)FeGtiqCrt3 zpe7AyO6@7G^qjP(Yjd{tG-tJyZQV94D%jd?x@%8!cI`@!)`rp_*miBYi)HV9-+L$b zUFHjNwEykPnR(y$dH3CS-+e#6zux4*m9;nK1pZ@zXzGs5aJrju-WmK=E;V-1l;<9|f%R_M)&y`>n$2(6PsC z`q=I*^Xx&*Cy#cWJb7}~Wj$DU_0Hc_gGH(JtM}X!itT(k5<7I`1lSD~bwj<&Ap$!d z05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z?gB5y(<|0PZnnSa$DAvOQ}-gWp@-Iw=!HzYn9DPr4+pvGAFA^tTF79mAM4=qg+%-)H@|Q~5kBBm$SOQW@NS z7F`Dix%?MScoO{l3;l;>xjg$1ZC6#;f}wdfGWFDtc-gfTKDs L | N (k', v, l, r) when Ord.compare k k' < 0 -> - N (k', v, delete k l, r) + N (k', v, delete k l, r) | N (k', v, l, r) when Ord.compare k k' > 0 -> - N (k', v, l, delete k r) + N (k', v, l, delete k r) | N (_, _, l, L) -> l | N (_, _, L, r) -> r | N (_, _, l, r) -> let (ks, vs) = largest l in - N (ks, vs, delete ks l, r);; + N (ks, vs, delete ks l, r);; (** [of_list l] takes a list of pairs [l] and creates a * kvtree in the order specefied by the comparator [] to compare diff --git a/lab05/kvtree/kvtree.mli b/labs/05/kvtree/kvtree.mli similarity index 100% rename from lab05/kvtree/kvtree.mli rename to labs/05/kvtree/kvtree.mli diff --git a/lab05/kvtree/tests.ml b/labs/05/kvtree/tests.ml similarity index 100% rename from lab05/kvtree/tests.ml rename to labs/05/kvtree/tests.ml diff --git a/lecture01/notes.ml b/lectures/01/notes.ml similarity index 100% rename from lecture01/notes.ml rename to lectures/01/notes.ml diff --git a/lecture01/tinker.ml b/lectures/01/tinker.ml similarity index 100% rename from lecture01/tinker.ml rename to lectures/01/tinker.ml diff --git a/lecture02/html/Length.html b/lectures/02/html/Length.html similarity index 100% rename from lecture02/html/Length.html rename to lectures/02/html/Length.html diff --git a/lecture02/html/index.html b/lectures/02/html/index.html similarity index 100% rename from lecture02/html/index.html rename to lectures/02/html/index.html diff --git a/lecture02/html/index_attributes.html b/lectures/02/html/index_attributes.html similarity index 100% rename from lecture02/html/index_attributes.html rename to lectures/02/html/index_attributes.html diff --git a/lecture02/html/index_class_types.html b/lectures/02/html/index_class_types.html similarity index 100% rename from lecture02/html/index_class_types.html rename to lectures/02/html/index_class_types.html diff --git a/lecture02/html/index_classes.html b/lectures/02/html/index_classes.html similarity index 100% rename from lecture02/html/index_classes.html rename to lectures/02/html/index_classes.html diff --git a/lecture02/html/index_exceptions.html b/lectures/02/html/index_exceptions.html similarity index 100% rename from lecture02/html/index_exceptions.html rename to lectures/02/html/index_exceptions.html diff --git a/lecture02/html/index_extensions.html b/lectures/02/html/index_extensions.html similarity index 100% rename from lecture02/html/index_extensions.html rename to lectures/02/html/index_extensions.html diff --git a/lecture02/html/index_methods.html b/lectures/02/html/index_methods.html similarity index 100% rename from lecture02/html/index_methods.html rename to lectures/02/html/index_methods.html diff --git a/lecture02/html/index_module_types.html b/lectures/02/html/index_module_types.html similarity index 100% rename from lecture02/html/index_module_types.html rename to lectures/02/html/index_module_types.html diff --git a/lecture02/html/index_modules.html b/lectures/02/html/index_modules.html similarity index 100% rename from lecture02/html/index_modules.html rename to lectures/02/html/index_modules.html diff --git a/lecture02/html/index_types.html b/lectures/02/html/index_types.html similarity index 100% rename from lecture02/html/index_types.html rename to lectures/02/html/index_types.html diff --git a/lecture02/html/index_values.html b/lectures/02/html/index_values.html similarity index 100% rename from lecture02/html/index_values.html rename to lectures/02/html/index_values.html diff --git a/lecture02/html/style.css b/lectures/02/html/style.css similarity index 100% rename from lecture02/html/style.css rename to lectures/02/html/style.css diff --git a/lecture02/html/type_Length.html b/lectures/02/html/type_Length.html similarity index 100% rename from lecture02/html/type_Length.html rename to lectures/02/html/type_Length.html diff --git a/lecture02/lists.ml b/lectures/02/lists.ml similarity index 100% rename from lecture02/lists.ml rename to lectures/02/lists.ml diff --git a/lecture02/notes02.ml b/lectures/02/notes02.ml similarity index 100% rename from lecture02/notes02.ml rename to lectures/02/notes02.ml diff --git a/lecture03/notes03.ml b/lectures/03/notes03.ml similarity index 100% rename from lecture03/notes03.ml rename to lectures/03/notes03.ml diff --git a/lecture04/bstree.ml b/lectures/04/bstree.ml similarity index 100% rename from lecture04/bstree.ml rename to lectures/04/bstree.ml diff --git a/lecture04/bstree.mli b/lectures/04/bstree.mli similarity index 100% rename from lecture04/bstree.mli rename to lectures/04/bstree.mli diff --git a/lecture04/notes.ml b/lectures/04/notes.ml similarity index 100% rename from lecture04/notes.ml rename to lectures/04/notes.ml diff --git a/lectures/05/_build/_digests b/lectures/05/_build/_digests new file mode 100644 index 0000000..de7371b --- /dev/null +++ b/lectures/05/_build/_digests @@ -0,0 +1,25 @@ +"Resource: /home/flami/Projects/comp3958/lecture05/number_lines.ml": "n\239\025\\<\011\028#\000A>\249\204\182\170r" +"Rule: ocaml dependencies ml (%=cat )": "\210V\221`\251\191B\198\232\184\146#\164\015\176," +"Rule: ocaml: cmx* & o* -> native (%=number_file_lines )": "R|\021U[G\226zs:\214\154\1910a\177" +"Rule: ocaml: ml & cmi -> cmx & o (%=cat )": "\025\244\2354\235@{lBk\211\031$\237><" +"Rule: ocaml: cmx* & o* -> native (%=number_lines )": "\180K\170\211^n:g\196\220\030 \233\127*\149" +"Rule: ocaml: cmx* & o* -> native (%=echo )": "\196\206\211\186\185&f\154\217p\215\195\248p\1485" +"Resource: /home/flami/Projects/comp3958/lecture05/echo.ml": "h\001\167\215xe\171\150p\151\004p>\004%\181" +"Rule: ocaml dependencies ml (%=sum_integers )": "\207\140\220\182.\186\127\200\228\226\152\002dAJ\134" +"Rule: ocaml dependencies ml (%=echo )": "\237\219\161\187\134\217\180\030\148\240\0166\176W\2222" +"Resource: /home/flami/Projects/comp3958/lecture05/sum_integers.ml": "#b[\196\162u!\202\205~\135\239\025i\195\215" +"Rule: ocaml: ml -> cmo & cmi (%=sum_integers )": "\015x\165\015\217\024\189(\143ud\232#\158Um" +"Rule: ocaml: cmx* & o* -> native (%=sum_integers )": "q.\011\170\190\228da(\218\172\231\192\136\236+" +"Rule: ocaml: ml -> cmo & cmi (%=cat )": "\248U3\213\015A\001\180 \023\180>\223}\142\188" +"Rule: ocaml: ml -> cmo & cmi (%=number_file_lines )": "\218\210>\023\150\016u\174\235\179&6\234\147\248\016" +"Rule: ocaml: ml & cmi -> cmx & o (%=echo )": "\1770\n\142p\235j\205HX\163\208\005\133n\t" +"Rule: ocaml: ml & cmi -> cmx & o (%=sum_integers )": "\024\022\151\178THu\229\251\017\175G\230\179rD" +"Rule: ocaml dependencies ml (%=number_lines )": "\023O8\158;\213,z\t`\236\204\250\168\140W" +"Resource: /home/flami/Projects/comp3958/lecture05/number_file_lines.ml": ":\233\133ai\245 \000\199f8\022\140<\199\174" +"Resource: /home/flami/Projects/comp3958/lecture05/cat.ml": "^\135\t\199Rr\210]\197\127HpY\r\147\170" +"Rule: ocaml: ml -> cmo & cmi (%=echo )": "\224\\C\014\150\004=\191p\132*-\017jj\242" +"Rule: ocaml dependencies ml (%=number_file_lines )": "\142\151\154\251\184\227\201\196\243\150\003\242\017\222\229X" +"Rule: ocaml: ml & cmi -> cmx & o (%=number_lines )": "l\154\251\180\134\026\206s\139\030!A\155\t\198\161" +"Rule: ocaml: ml -> cmo & cmi (%=number_lines )": "\029\1849 z\004\n\025\253\155]\017\244\252\141\129" +"Rule: ocaml: cmx* & o* -> native (%=cat )": "j\019\018\218,\202\215\161 &5SE\134\223/" +"Rule: ocaml: ml & cmi -> cmx & o (%=number_file_lines )": "|\132>\000@\222\195L,\1271\1424\141wJ" diff --git a/lectures/05/_build/_log b/lectures/05/_build/_log new file mode 100644 index 0000000..57df0fc --- /dev/null +++ b/lectures/05/_build/_log @@ -0,0 +1,12 @@ +### Starting build. +# Target: /home/flami/.opam/default/bin/ocamlc.opt -config, tags: { } +/home/flami/.opam/default/bin/ocamlc.opt -config +# Target: number_lines.ml.depends, tags: { extension:ml, file:number_lines.ml, ocaml, ocamldep, quiet } +/home/flami/.opam/default/bin/ocamldep.opt -modules number_lines.ml > number_lines.ml.depends +# Target: number_lines.cmo, tags: { byte, compile, extension:cmo, extension:ml, file:number_lines.cmo, file:number_lines.ml, implem, ocaml, quiet } +/home/flami/.opam/default/bin/ocamlc.opt -c -o number_lines.cmo number_lines.ml +# Target: number_lines.cmx, tags: { compile, extension:cmx, extension:ml, file:number_lines.cmx, file:number_lines.ml, implem, native, ocaml, quiet } +/home/flami/.opam/default/bin/ocamlopt.opt -c -o number_lines.cmx number_lines.ml +# Target: number_lines.native, tags: { dont_link_with, extension:native, file:number_lines.native, link, native, ocaml, program, quiet } +/home/flami/.opam/default/bin/ocamlopt.opt number_lines.cmx -o number_lines.native +# Compilation successful. diff --git a/lectures/05/_build/cat.cmx b/lectures/05/_build/cat.cmx new file mode 100644 index 0000000000000000000000000000000000000000..964d9cdad41f17c0d36fee19fec99babb9444d05 GIT binary patch literal 218 zcmZ=x%*`>hw6u&gFg9zMx@;c<1H&pHmI2}%Adcl=V9;k!c1|o|VO+q%!;|`MfI&zlAXM3n`wQdxiJ=y9Em@oPkzk z=9Q!t ();; (* EOF return unit *) + +(* similar to main function *) +let () = + let rec aux () = + try + print_endline @@ read_line (); + aux () + with + | _ -> () + in + aux() + +(**** build and test ****) +(* + ocamlbuild cat.native + ./cat.native < filename +*) diff --git a/lectures/05/_build/cat.ml.depends b/lectures/05/_build/cat.ml.depends new file mode 100644 index 0000000..832688d --- /dev/null +++ b/lectures/05/_build/cat.ml.depends @@ -0,0 +1 @@ +cat.ml: diff --git a/lectures/05/_build/cat.o b/lectures/05/_build/cat.o new file mode 100644 index 0000000000000000000000000000000000000000..ef4132e813a8d9385dd37a6f025dd68b80fc0605 GIT binary patch literal 3224 zcmchZO>7%g5P-*ZXieI5{A>xLf~{%OO1*6_`C@(cLOytfRKsLNIka;O(FJ;f(d*MMqlTE`$m zafg=SQPj6y%tFl#?IsT3&wjuED%$P`J@}PvY=hg8jnPV0Sp#B{%j$`bgWQm~bRH5t zD{*+=p40|zsw{Hqi{t`5-cDPS>5NOy)NIK&o|8~%pH zkKjTN;|CQ_!0zZpa5aFViYEv2l!iR=M{vFi3~ot7&20uw%Uf(XO}G0#?sIhAYFBe< zyPs4IWQ`B3x*NJq)m!vi15|6*JrlX1bMnmTK?oik^v{Sd+Fq)Coz3eF%N@TJI$jH-s4;(5H99pn2pmibf_Ba6hHfpI4-MOEg`E{}rYp1O ziWO(JRGOQbcjk-dDpO9B>$m*ScLV>Dr+ms$v%yXVK+RYOjgH&&Lbn=tvYbcR7(qRT zzrXn4Kdte!#^sKpc)9~6{tYdDzs5h)xL*GYjqCNVYJ60yv#D{t{twJ)ymaTwcx1m2 zr%!|MpV20v@gKmS@OuPNi0l2{S2W^!zj80ocBXX@$+AJ5>WCEBAg+I^mNdQ#?cdq& z8T=aipBwy3_NATbQ=K*D*I5gnV1LWtHv2aXew_U*YpP8@kx4d$FR(B3628qG?Cwev zcOdGp6X_+fI$q$~q1OumPZFB6eZj7FyXd#cv1{FMJP&rO9eVck>u;Wj&P){TEjem? zOGp1rXEB}D%=}^$kdc`8n0eC4eWiReT=G}3O&6KJuz56wt>1MHEOQ{OA0f$?_cyF>O3CtqT0Ahi3+R=Y i`E;k4YmW$WbjhL27>i@L`0X5?f0sL|sVecq%>Nst7Pip< literal 0 HcmV?d00001 diff --git a/lectures/05/_build/echo.cmx b/lectures/05/_build/echo.cmx new file mode 100644 index 0000000000000000000000000000000000000000..34c2dfd4d8df8787a144a8c27adc7b497a68586c GIT binary patch literal 489 zcmZ=x%*`>hw6u&gFg9zMx@;c<1LIBx1_l=(4Wt+@aWF9GGpM*GXXLXmE?{ADSg=4h zxFjVfGbuhkG&v)&XoA7FCB7F9Jvzbda_?>3=7Wmw7c9_*sR*tto?x(|tMonpiYGP? zayj<=-LoeOSw6LJf`P1z;REe*cK#1f{-VWSdo;tW|m~60$p+8s>_YFIX5m(%=^ajqOQ9VNr_WwS{g`+hnLiX1!@qdOfaa_+`2nfe?h&+ z1sR|22HCs?3s`g}7&!eZG@9l0Nsr^ft@y=BN^T1lSU3X%6zJ;IqP)Z$xBQ~q#1f~( z;>=`VK*XOmk>pC+TT7%Q6oAKxOPn@1CgR7?0$XYz;>T)e8xjRoPE{u>aA}}v1gK)W-fWyu$40vg zBnYX2NJWu_$N>q&g>a&G4n%MuRXCJeZ$t47KBzW2WO z-u&(C*q8H#p_W*TNr|zOEc7I0Y;u2S=eU_;cd`yv_~?_&)$K;(%)nT8=Lee*G3Rfk zzsD}j+CEHN$A>w;Qa5YNytdwM&R>s#yZv1&^8VG%kH17?;X)>1E}YJ!%!Nalz4f(M z>gKhLcC+?e#_a#6^UC{JQ#-x9WiG@sU_f#00u=YJ1(5V0MA=3g88i{IHg^=}CFZlR zYSsqKT0GPE2@7H9HFJKoMNFgi9`;lZ4xAY{+4vWl9qTd?2fg7NZH(XvKFT%d^N$D1oE|M@1o$azehRh%G6z6UL$`+#vOaQY*pOSgf(sZml${L zqOZ94nPvNUgqyvg`D|#O2+iZ6`AldY3(cO;9Jd48D!QeqO30k*xT~=+SaK|{S`GY= zxRt=0W!7-v?5V+mb#`dzTz=FV9XwUYTRh3~XMM}|N^c9#u^hWx=C-(86m#dEnGhF^ zb^Mr^E3dIij_3k*%=SEc)+$!ts*GE%=T$xG9J;nV7oJte@&nruJIeQsFUzfr^Gr_o z;&+h=&z^PzyI6MV{X9e(zh}I=w&)@|LOc!{e={V1ow%OwG|B%|$;V$P+0T-~@ivnD zD}~>y@UMyEeC|{DUkXnvd|To7D|{cEQxxpy0cdhu`MqOU{Z0(Yr#M1~sBrge< zb!+@_;s$9P6Wfkt{n=?aP%P^Qp3sxh^4zkW4cwW4Wx0vRk!6d%4}KM$tm6kgy)0X) z25xrv#q&>#6D_jcNsFJ>oss^RVL&x5P5t)K(#2P}6 zv0iX+h%Oa^y-D?k#^pC8^=XJ}OXL+PeL~cap8G1*>(iC>IjWONu3!42U_|ZTdb`Mw z`-JZgYh}IUI3Im%tQ?{F-=HA=olZj2>v5QUC(gBAdXNwPrd$M DB7V=- literal 0 HcmV?d00001 diff --git a/lectures/05/_build/number_file_lines.cmx b/lectures/05/_build/number_file_lines.cmx new file mode 100644 index 0000000000000000000000000000000000000000..99114530e2355def67a31d966eb79a22cb4eb29c GIT binary patch literal 548 zcmZ=x%*`>hw6u&gFg9zMx@;c<1LGG41_m!6Ef1vMa4<0FGZ^}n<|d^U#iwQFq{ioD z=A{<1FfL$Wa#*lHH@GAvCo?HNJ~TNav1o$9wUoT57$neR*s{$+3hgwc>nH#seeS^k=gEzstyaBK*(Xj x#0d)?a4IANU4s#mdU=qzH8MAGa&&NXbZ~H(a$es!W!0sb6{^{t=iWY@3ILry=XL-9 literal 0 HcmV?d00001 diff --git a/lecture05/number_file_lines.ml b/lectures/05/_build/number_file_lines.ml similarity index 100% rename from lecture05/number_file_lines.ml rename to lectures/05/_build/number_file_lines.ml diff --git a/lectures/05/_build/number_file_lines.ml.depends b/lectures/05/_build/number_file_lines.ml.depends new file mode 100644 index 0000000..ae47d2a --- /dev/null +++ b/lectures/05/_build/number_file_lines.ml.depends @@ -0,0 +1 @@ +number_file_lines.ml: Array Printf Sys diff --git a/lectures/05/_build/number_file_lines.o b/lectures/05/_build/number_file_lines.o new file mode 100644 index 0000000000000000000000000000000000000000..498f5ee3e01d084c79e7ad49cd2b58a4c20749ed GIT binary patch literal 5768 zcmbuDeTZAd7QiRTYSXVY^(l?oYP6}Qis5dz-EI+OQ}*N5My+xCp#iI zkbCC*&c~dY`!V-sx;N7o3h<=U+_Jeyi7Szxhyd z!&CnQi#_{&+@9-6MD4jRP{uOPZ#fJ+eK1`=V(pt7vCd#TH`&#m1UXl?a9X`ch#3p2 zAjgl;EoxUENW=u;QL`t4h>{$oU+A;!*^}XO`!`(8Y?)*}2}$hg(L{`p2%lXJR5q=E zPsSH(3pjbm6ki;vadG&1F~EIix7O?R8qW9i#(Xzn{@L%tc6FC1`xY+dzS&nD=@x^{ zef2(1DQcnuPAuD1W`A&IwLSZBz@A+WO>AiteGH3U2tgw5eD)RS!4eLDXf9!E&g$T@ z{p2t8Rg4{(wyTrj_gY4sTWn@+tk*ufDr&Ae2kfe4?>RlO-L7_r?YXvuEzij_U672X zvuIauwySN4`se4?!z?Y#l)gV*|3UF@9dYbT+S2K|k6*WzuXwrfDSRAH$9q&T4dUq#2fy8fwRPbz)v zZijJWASX4x2RQo982Dfd4?>@0$Gb5V0n}q zV{91ZzhdkGkPFc`tAQL_eQM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P=-` sU(mwh|4aBEj~>4on7;Oan2iHMyH_*nYlS&A7aq4n^=G-(Jm~Si1LBm?AOHXW literal 0 HcmV?d00001 diff --git a/lectures/05/_build/number_lines.cmx b/lectures/05/_build/number_lines.cmx new file mode 100644 index 0000000000000000000000000000000000000000..b3099899455484b1a7bea7c341f45063b8a6ec65 GIT binary patch literal 411 zcmZ=x%*`>hw6u&gFg9zMx@;c<17kJ=1A{pbUjpJa91INl3_5WP0mOxnqcs4iSLC&k4|vA+1{AHM1lm z6==(at1dUz=G?eEG4C78i@NSgBqdIzX=xxOl2Z*EZA5yCt(LS%GJcb2U9dn6V$lSH zO3kgiWAzu*dt8w5>28qCTd;sdX@bEu8!bhdbLFMY9|a%po1kB|V1b1*Fj#vW3hfvIPIm5M5IqGU>R=uyv zc!uNxyB&rd@84Z8^^XWVGTXgT)xlwblY_&Ai46`8sg+xuYXdf!luUT_cFD4zHvr?F BtNj1~ literal 0 HcmV?d00001 diff --git a/lecture05/number_lines.ml b/lectures/05/_build/number_lines.ml similarity index 100% rename from lecture05/number_lines.ml rename to lectures/05/_build/number_lines.ml diff --git a/lectures/05/_build/number_lines.ml.depends b/lectures/05/_build/number_lines.ml.depends new file mode 100644 index 0000000..8142677 --- /dev/null +++ b/lectures/05/_build/number_lines.ml.depends @@ -0,0 +1 @@ +number_lines.ml: Printf diff --git a/lectures/05/_build/number_lines.o b/lectures/05/_build/number_lines.o new file mode 100644 index 0000000000000000000000000000000000000000..f825a76adacedf886f520800dd40f72545559492 GIT binary patch literal 3752 zcmbuCO>7%g5P-){+87cXxBR&ZRTe3&LIKP9X_^WN*-_#c$s`d8RiKrYwY|OEFaBvFn%ue{c+}n93!;7W!Uwq>p_b3fq<4Q^sMTuSz2hLpyU*h-hwimu zhayMR9xT7e1&@BFk)Zsg&6|8NLck@W%4TBZtCS<==PqV%Sm!EFGVf@AT3Y6sn|^1D zcKyuF{4VCtaz`qD)FHtQOXw58d1^W>x>57y)&QPB>ss9d7--@TAB+1Sj6VHzp}H6F zw}QX$#ABF2y?e$2svQj^Ax8ce7L1Y(_d{{Dkao*F$!&UE30hOZ{_$Ycf0YzEfq2kLi04?ae==xI1Ooun-W=tlyhM-pf}u$Y{EM{1 zAGK!Twx(|~;L%mP-Kdi1<75M{6%zU+NZknc3bPH&kqt7Z{nBMZIBl?~L$v3a)4uC+ zT{vy><n!#f!#&8U z9jlQltXEp_gy2Rpx^@e`+JbMk;9s`jw_ET7!d51tG~*T%Oc|#8ug+PFS_JK1738|iw3=D z*o%g|DC<-mJMAtk6}_=cDeJb1;mu?ZUh?+gZDk>2mrJE;MMUH+7Ad<mx+)P$|2Yi9la%gGDS9v+elWIHP>`E|JrcE-u)ZR{hTFJ$JGLQiv07gDj#kXsEoQwDu~JPVxw2Dmt4=!a@_CW>3P3yhbVnZX1)Svg1=RGX zP4Q`sKd14l%&DE{HD1toSmPgQ{FKJO()byT-`BXF|DDG5e06`)>p}TSEH;RrRuHwi zSBcXtuI|$q+9Zmr`*cO(I)BLirongES6a2B?$cc(e~7;EL{21AsSb=lq*$uDk;$pIUzIP0%yt)Taf;Ol{-3t6oThC4g^nR3 zG4JD$#Pw$nT6E@Pbs~+ufYfTA>BE%zVO;-SdzrcUISP>_pa$KeL{;so7N5_&{DT V8aLO9?zU$2>i>@n#&t34{{b5r06G8w literal 0 HcmV?d00001 diff --git a/lectures/05/_build/sum_integers.cmx b/lectures/05/_build/sum_integers.cmx new file mode 100644 index 0000000000000000000000000000000000000000..f564928b8940338d93f0723d5cb357b28b05ecdb GIT binary patch literal 477 zcmZ=x%*`>hw6u&gFg9zMx@;c<1LIl-1_lQp{tCp$IT#r98FYe6bK^7fN>bBPi;7to z7qBonELgz8GQr?;-o?$~4euomFMo35RL9=03l``Gm!#xmCdJ2xCTAoTO)&Vj#P`CX zM<=*l?!B$sd{FWIf(666AWZ!3?FEhv-5v=Dz|F2)`v4lCIlxZ=A}(A(3@^K zy=T>ChxR+oj$P;GK3lLr4`xC@5ztXUB^lGEBv^U`%zJ!c^Xys25?GOxxMr4QqypV> z;i}7xwK+E~Pt5zq@}jQ05=n_uX<8aciR4tnMjMfyVyh)Bl8oOZS{E!(gIF}dpi*<| z?pXZ=^&S^we7YNC^A;?ya0Uh(C`gL(5_8=0i*gf7oDz#OlZz)9#Gf{iT^VC@`$xp#t^OdxqzMrz47$OPm&WEI<445Rz+PeiDkAE@!w_Do0)I%&PZQ89;Bt vU1PVyu;cx^3#R@Nfk$S$H>x@S!Gwto4i1xeV-#}lUb+7I=9P@}kXL&Eg$U09 literal 0 HcmV?d00001 diff --git a/lecture05/sum_integers.ml b/lectures/05/_build/sum_integers.ml similarity index 100% rename from lecture05/sum_integers.ml rename to lectures/05/_build/sum_integers.ml diff --git a/lectures/05/_build/sum_integers.ml.depends b/lectures/05/_build/sum_integers.ml.depends new file mode 100644 index 0000000..55eb6ca --- /dev/null +++ b/lectures/05/_build/sum_integers.ml.depends @@ -0,0 +1 @@ +sum_integers.ml: Printf Scanf diff --git a/lectures/05/_build/sum_integers.o b/lectures/05/_build/sum_integers.o new file mode 100644 index 0000000000000000000000000000000000000000..f8a1a49e05a82c8f5e64d9055c0a4f21294992df GIT binary patch literal 5056 zcmbuDZ)j6j6u@uVPNS=7bZ(1tu0hgKHw>+<+S*N;+CQ%&YOzi_J9tggq^%}tNzzgG z2ZNQZAuB7W;Py%OLEHvoOc)NvR;V!d5BALt1{?ULWdofX*bicM&VA=Jw>K~I!!G2V zbARX0z3<%j?tSg)j$mh*!y&ji#C}oeF%=@?F6gaNZ510tr3lWP_g#9B&mU|#R$FzZ z211RgKix*Q-RBI>Y0dsWL$ZeB;IY^kRGnyYv1PscSt?;enziK6(!o)`Q?^U@geEFL=f^%tG zKA*3uh6zy4{yw95VWLtRVNCaYbhbMet-~n<`UCk}=!;mUTPlO-6E)T(k1zcM#fwJ$ zRn=#4evq@@ZOpWn=jWqU)$KxD!^M~{*sN2OS~@Jf{80t#iPuXxOw2#>2vnx=S|AIGsj%XO@f+z9fz!Zy;|Ijt~M(J!X3 zEug2hzG~kAHdzt!!Tt-1{|*=jU->45q52&B9PskZf?OWy6GuUMI+n!<$m!i)F#xi5 zOOrSY@Q`Qt~hD|og z){+HYE!A?N&#r;Ex8N$ZF5+_% z@kNdQNPI!#zY*`zUg*2T^-`~qe&wQ8^M8uCN8^6zyKUCxCCN2s7&8iJ6AU^)CSJMI z#CiJinT5_p;Fw>3&p#@`=OyPX1^El*=Q{ASeYb>v1?(aEvxC{Tm*6`~@O>rt5#U&d zaTp()e1|}emhhjJ+#!A-e;EXq4<#=blN$dD_(rH(hWH5E!=ZT0OhksGW;~QSDP%V^ zm{Pi{wy*j|>9U$N6f+yQred$=Vzj3i?JY*Ti_xxPWHYb&Vy}9e$oe`PKbzR0P&#A| zMutZd#s1;3p-3rPbRuCkG}_D$jt6ts-s0*NrymZR$+59?N|;^2!)<|}dAPH)x8taJ zG|(38FpK@=kPWm5bXv(%#&T7O|D-&4%=)HgS|Mqbj%GL%iBwvjW1IFhQ=4D ze@Ekde#jdF8|UZq(uqLfd|tL{yvK4Aye?>lEn9p+et7O-WBxJqKhyZT)SuJ%Z7W>- ztnpjKf7kf?#P4YQJaIWW(9w+Ze22IPJJ6W#qIj>QmM^(T(x-8*Cx82+Fa8E7Pe$_} zCocS{Q*n6pL8g>$YfghrHUJf@DHX^&>zE&Kb%U}?-BmQSUTeGI`r~R zYbUe3BO|8VS7_k>DZCJmQ|9j+PS;9`exAG8fh6u__)fJ_pG9q@rSWsJ9=bS=lN|Wn zd7ilbZcM*_JQM8VJyhVZ%u=}M@&5uO Cvi^<$ literal 0 HcmV?d00001 diff --git a/lecture05/cat.ml b/lectures/05/cat.ml similarity index 100% rename from lecture05/cat.ml rename to lectures/05/cat.ml diff --git a/lecture05/data.txt b/lectures/05/data.txt similarity index 100% rename from lecture05/data.txt rename to lectures/05/data.txt diff --git a/lectures/05/echo.ml b/lectures/05/echo.ml new file mode 100644 index 0000000..b2774fd --- /dev/null +++ b/lectures/05/echo.ml @@ -0,0 +1,6 @@ +let () = + let len = Array.length Sys.argv - 1 in + for i = 1 to len do + Printf.printf (if i <> len then "%s " else "%s\n") Sys.argv.(i) + done;; + diff --git a/lecture05/notes.ml b/lectures/05/notes.ml similarity index 99% rename from lecture05/notes.ml rename to lectures/05/notes.ml index bdf4153..2711f6e 100644 --- a/lecture05/notes.ml +++ b/lectures/05/notes.ml @@ -158,4 +158,3 @@ Scanf.scanf " %d" (fun x -> x) (* open_in "filename";; *) let ic = open_in "output";; input_line ic;; - diff --git a/lectures/05/number_file_lines.ml b/lectures/05/number_file_lines.ml new file mode 100644 index 0000000..477043c --- /dev/null +++ b/lectures/05/number_file_lines.ml @@ -0,0 +1,16 @@ +let rec number acc ic = + try + Printf.printf "%5d| %s\n" acc @@ input_line ic; + number (acc + 1) ic + with + | _ -> if ic <> stdin then close_in ic else () + +let () = + if Array.length Sys.argv = 1 then + number 1 stdin + else + try + number 1 @@ open_in Sys.argv.(1) + with + | Sys_error s -> Printf.eprintf "%s\n" s;; + diff --git a/lectures/05/number_lines.ml b/lectures/05/number_lines.ml new file mode 100644 index 0000000..4028e41 --- /dev/null +++ b/lectures/05/number_lines.ml @@ -0,0 +1,9 @@ +let () = + let rec aux acc = + try + Printf.printf "%5d| %s\n" acc @@ read_line (); + aux (acc + 1) + with + | _ -> () + in + aux 1;; diff --git a/lecture05/output b/lectures/05/output similarity index 100% rename from lecture05/output rename to lectures/05/output diff --git a/lecture05/ref.ml b/lectures/05/ref.ml similarity index 100% rename from lecture05/ref.ml rename to lectures/05/ref.ml diff --git a/lectures/05/sum_integers.ml b/lectures/05/sum_integers.ml new file mode 100644 index 0000000..d9b5fac --- /dev/null +++ b/lectures/05/sum_integers.ml @@ -0,0 +1,12 @@ +let () = + let rec aux sum = + try + aux @@ Scanf.scanf " %d" (fun x -> sum + x) + with + | Scanf.Scan_failure _ -> + Scanf.scanf " %s" (fun _ -> ()); + aux sum + | End_of_file -> sum + in + Printf.printf "%d\n" @@ aux 0;; + diff --git a/lectures/06/_build/_digests b/lectures/06/_build/_digests new file mode 100644 index 0000000..a316040 --- /dev/null +++ b/lectures/06/_build/_digests @@ -0,0 +1,3 @@ +"Rule: ocaml dependencies ml (%=two_list_queue )": "\153s\252\225.\205\197\1597\030\142\254Q\213.\135" +"Resource: /home/flami/Projects/comp3958/lecture06/two_list_queue.ml": "\174\189*\255(\166==\251\006\232\150\141\1714\130" +"Rule: ocaml: ml -> cmo & cmi (%=two_list_queue )": "9\165\179\031F'#6\127\149\136<\242y\019t" diff --git a/lectures/06/_build/_log b/lectures/06/_build/_log new file mode 100644 index 0000000..9d0e2de --- /dev/null +++ b/lectures/06/_build/_log @@ -0,0 +1,8 @@ +### Starting build. +# Target: /home/flami/.opam/default/bin/ocamlc.opt -config, tags: { } +/home/flami/.opam/default/bin/ocamlc.opt -config +# Target: two_list_queue.ml.depends, tags: { extension:ml, file:two_list_queue.ml, ocaml, ocamldep, quiet } +/home/flami/.opam/default/bin/ocamldep.opt -modules two_list_queue.ml > two_list_queue.ml.depends +# Target: two_list_queue.cmo, tags: { byte, compile, extension:cmo, extension:ml, file:two_list_queue.cmo, file:two_list_queue.ml, implem, ocaml, quiet } +/home/flami/.opam/default/bin/ocamlc.opt -c -o two_list_queue.cmo two_list_queue.ml +# Compilation successful. diff --git a/lecture06/two_list_queue.ml b/lectures/06/_build/two_list_queue.ml similarity index 100% rename from lecture06/two_list_queue.ml rename to lectures/06/_build/two_list_queue.ml diff --git a/lectures/06/_build/two_list_queue.ml.depends b/lectures/06/_build/two_list_queue.ml.depends new file mode 100644 index 0000000..0d870ba --- /dev/null +++ b/lectures/06/_build/two_list_queue.ml.depends @@ -0,0 +1 @@ +two_list_queue.ml: Fun List diff --git a/lecture06/bstree.ml b/lectures/06/bstree.ml similarity index 100% rename from lecture06/bstree.ml rename to lectures/06/bstree.ml diff --git a/lecture06/bstree.mli b/lectures/06/bstree.mli similarity index 100% rename from lecture06/bstree.mli rename to lectures/06/bstree.mli diff --git a/lecture06/bstree2.ml b/lectures/06/bstree2.ml similarity index 100% rename from lecture06/bstree2.ml rename to lectures/06/bstree2.ml diff --git a/lecture06/functor/_build/_digests b/lectures/06/functor/_build/_digests similarity index 100% rename from lecture06/functor/_build/_digests rename to lectures/06/functor/_build/_digests diff --git a/lecture06/functor/_build/_log b/lectures/06/functor/_build/_log similarity index 100% rename from lecture06/functor/_build/_log rename to lectures/06/functor/_build/_log diff --git a/lecture06/functor/_build/bstree.ml b/lectures/06/functor/_build/bstree.ml similarity index 100% rename from lecture06/functor/_build/bstree.ml rename to lectures/06/functor/_build/bstree.ml diff --git a/lecture06/functor/_build/bstree.ml.depends b/lectures/06/functor/_build/bstree.ml.depends similarity index 100% rename from lecture06/functor/_build/bstree.ml.depends rename to lectures/06/functor/_build/bstree.ml.depends diff --git a/lecture06/functor/_build/bstree.mli b/lectures/06/functor/_build/bstree.mli similarity index 100% rename from lecture06/functor/_build/bstree.mli rename to lectures/06/functor/_build/bstree.mli diff --git a/lecture06/functor/_build/bstree.mli.depends b/lectures/06/functor/_build/bstree.mli.depends similarity index 100% rename from lecture06/functor/_build/bstree.mli.depends rename to lectures/06/functor/_build/bstree.mli.depends diff --git a/lecture06/functor/bstree.ml b/lectures/06/functor/bstree.ml similarity index 100% rename from lecture06/functor/bstree.ml rename to lectures/06/functor/bstree.ml diff --git a/lecture06/functor/bstree.mli b/lectures/06/functor/bstree.mli similarity index 100% rename from lecture06/functor/bstree.mli rename to lectures/06/functor/bstree.mli diff --git a/lecture06/notes.ml b/lectures/06/notes.ml similarity index 100% rename from lecture06/notes.ml rename to lectures/06/notes.ml diff --git a/lecture06/notes.txt b/lectures/06/notes.txt similarity index 100% rename from lecture06/notes.txt rename to lectures/06/notes.txt diff --git a/lecture06/queue.ml b/lectures/06/queue.ml similarity index 100% rename from lecture06/queue.ml rename to lectures/06/queue.ml diff --git a/lectures/06/two_list_queue.ml b/lectures/06/two_list_queue.ml new file mode 100644 index 0000000..48eff0c --- /dev/null +++ b/lectures/06/two_list_queue.ml @@ -0,0 +1,42 @@ +(* queue is empty iff the first list is empty *) +type 'a t = 'a list * 'a list;; + +exception Empty;; + +let empty = ([], []);; + +let is_empty (l, _) = l = [];; + +let enqueue x (l1, l2) = + match l1 with + | [] -> [x], l2 + | _ -> (l1, x :: l2);; + +let dequeue (l1, l2) = + match l1 with + | [] -> raise Empty + | [_] -> (List.rev l2, []) + | _ :: xs -> (xs, l2);; + +let dequeue_opt q = + try + Some (dequeue q) + with + | Empty -> None;; + +let front (l, _) = + match l with + | [] -> raise Empty + | x :: _ -> x;; + +let front_opt (l, _) = + match l with + | [] -> None + | x :: _ -> Some x;; + +let of_list l = + List.fold_left (Fun.flip enqueue) empty l;; + +let to_list (l1, l2) = + l1 @ List.rev l2;; + diff --git a/lectures/07/bstree.ml b/lectures/07/bstree.ml new file mode 100644 index 0000000..83ebf68 --- /dev/null +++ b/lectures/07/bstree.ml @@ -0,0 +1,2 @@ +(* bstree with records *) +type 'a t = L | N of {v: 'a; l: 'a t; r: 'a t};; diff --git a/lectures/07/counter.ml b/lectures/07/counter.ml new file mode 100644 index 0000000..402a668 --- /dev/null +++ b/lectures/07/counter.ml @@ -0,0 +1,7 @@ +let counter = + let c = ref 0 in + (fun () -> incr c; !c);; + +let make_counter init = + let c = ref init in + (fun () -> let x = !c in incr c; x);; diff --git a/lectures/07/frequency.ml b/lectures/07/frequency.ml new file mode 100644 index 0000000..d00826d --- /dev/null +++ b/lectures/07/frequency.ml @@ -0,0 +1,12 @@ +module F = Map.Make(String) + +let rec count map = + let word = Scanf.scanf " %s" (fun w -> w) in + if word = "" then map + else count (F.update word (function + | None -> Some 1 + | Some n -> Some (n + 1)) + map);; + +let () = + List.iter (fun (s, n) -> Printf.printf "%s: %d\n" s n) @@ count F.empty;; diff --git a/lectures/07/leftist.ml b/lectures/07/leftist.ml new file mode 100644 index 0000000..2ac4afa --- /dev/null +++ b/lectures/07/leftist.ml @@ -0,0 +1,46 @@ +(** rank of node = shortest distance to a leaf (empty node) + * hence, rank of node = 1 + min(rnak of left, rank of right) + * leftist tree has 2 properties: + * For ever node + * * leftist: rnak(left) >= rank(right) + * * min-heap: value(parent) <= value(node) + *) + +type 'a t = L | N of int * 'a * 'a t * 'a t;; + +exception Empty;; + +let rank = function + | L -> 0 + | N (rk, _, _, _) -> rk;; + +let empty = L;; + +let is_empty t = t = L;; + +let rec merge t1 t2 = + match t1, t2 with + | t, L | L, t -> t + | N (_, x1, _, _), N (_, x2, _, _) when x2 < x1 -> + merge t2 t1 + | N (_, x, l, r), t -> + let t' = merge r t in + if rank t' > rank l then N (1 + rank l, x, t', l) + else N (1 + rank t', x, l, t');; + +let insert x t = + merge t (N (1, x, L, L));; + +let of_list l = List.fold_left (Fun.flip insert) L l;; + +let get_min = function + | L -> raise Empty + | N (_, x, _, _) -> x;; + +let delete_min = function + | L -> L + | N (_, _, l, r) -> merge l r;; + +let rec to_list t = + if is_empty t then [] + else get_min t :: to_list (delete_min t);; diff --git a/lectures/07/modules.ml b/lectures/07/modules.ml new file mode 100644 index 0000000..6ffc1c9 --- /dev/null +++ b/lectures/07/modules.ml @@ -0,0 +1,47 @@ +(* + - a module can contain other modules as well as module type definitions + - a module type/sig (signature) can not contain modules but can contain other sigs + - for a .ml/.mli pair, + * anything not specified in .mli file is hidden + * everything specified in the .mli file must be defined in the .ml file +*) + +module M = struct + let f x = 2 * x +end;; + +module type S = module type of M;; + +module M = struct + let f x = 2 * x;; + let g x = 3 * x;; + module N = struct + type t = int + end +end;; + +(* S signature is the same as M if loaded in utop *) +module type S = module type of M;; + +(***** EXTENDED MODULES *****) + +(* lets extend List module *) +module ListExt = struct + include List;; (* include module to extend *) + let to_array l = Array.of_list l;; +end;; + +ListExt.to_array [3;2;7;6;8];; + +module F = Map.Make(String);; + +(* returns abstract type *) +let m = F.empty |> F.add "hello" 1 |> F.add "hello" 2;; +F.to_list m;; + +let incr key m = + F.update key (function | None -> Some 1 | Some x -> Some (x + 1)) + m;; + +let m = incr "hello" m;; +let m = incr "world" m;; diff --git a/lectures/07/sieve.ml b/lectures/07/sieve.ml new file mode 100644 index 0000000..0c409b0 --- /dev/null +++ b/lectures/07/sieve.ml @@ -0,0 +1,16 @@ +let isqrt n = n |> float_of_int |> sqrt |> int_of_float;; + +let sieve n = + let is_prime = Array.make n true in + for i = 2 to isqrt n do + if is_prime.(i) then + let j = ref i in + while i * !j < n do + is_prime.(i * !j) <- false; + incr j + done + done; + is_prime.(0) <- false; + is_prime.(1) <- false; + is_prime |> Array.to_list |> List.mapi (fun i b -> (i, b)) |> + List.filter_map (fun (i, b) -> if b then Some i else None);;