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.
18 lines
346 B
OCaml
18 lines
346 B
OCaml
(* Baseline: exception declaration + raise + try-with *)
|
|
exception NegArg of int ;;
|
|
let safe_sqrt n =
|
|
if n < 0 then raise (NegArg n)
|
|
else
|
|
begin
|
|
let rec find_sqrt i =
|
|
if i * i > n then i - 1
|
|
else find_sqrt (i + 1)
|
|
in find_sqrt 0
|
|
end ;;
|
|
let result =
|
|
try
|
|
safe_sqrt 16
|
|
with
|
|
| NegArg _ -> 0 ;;
|
|
result
|