ocaml: phase 5.1 baseline 8/8 — quicksort + exceptions + closures
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 38s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 38s
Added 3 baseline programs: - closures.ml — curried make_adder; verifies closure capture - quicksort.ml — recursive sort using List.filter + List.append, sums result - exception_handle.ml — exception NegArg of int + raise + try/with All 8/8 baseline programs pass through ocaml-run-program. Combined the suite exercises: let-rec, modules, refs, for-loops, pattern matching, exceptions, lambdas, list ops (map/filter/append/fold), arithmetic. run.sh streamlined to one sx_server invocation per program. End-to-end runtime ≈2 min.
This commit is contained in:
10
lib/ocaml/baseline/quicksort.ml
Normal file
10
lib/ocaml/baseline/quicksort.ml
Normal file
@@ -0,0 +1,10 @@
|
||||
(* Baseline: quicksort over a list, returns sum of sorted result *)
|
||||
let rec quicksort lst =
|
||||
match lst with
|
||||
| [] -> []
|
||||
| pivot :: rest ->
|
||||
let smaller = List.filter (fun x -> x < pivot) rest in
|
||||
let larger = List.filter (fun x -> x >= pivot) rest in
|
||||
List.append (quicksort smaller) (pivot :: quicksort larger) ;;
|
||||
let sorted = quicksort [3; 1; 4; 1; 5; 9; 2; 6; 5; 3; 5] ;;
|
||||
List.fold_left (fun a b -> a + b) 0 sorted
|
||||
Reference in New Issue
Block a user