ocaml: phase 6 Seq module (eager, list-backed) (+4 tests, 576 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s
Real OCaml's Seq.t is 'unit -> Cons of elt * Seq.t | Nil' — a lazy
thunk that lets you build infinite sequences. Ours is just a list,
which gives the right shape for everything in baseline programs that
don't rely on laziness (taking from infinite sequences would force
memory).
API: empty, cons, return, is_empty, iter, iteri, map, filter,
filter_map, fold_left, length, take, drop, append, to_list,
of_list, init, unfold.
unfold takes a step fn 'acc -> Option (elt * acc)' and threads
through until it returns None:
Seq.fold_left (+) 0
(Seq.unfold (fun n -> if n > 4 then None
else Some (n, n + 1))
1)
= 1 + 2 + 3 + 4 = 10
This commit is contained in:
@@ -1430,6 +1430,16 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 5182)
|
||||
(eval "(ocaml-run-program \"module IntOrd = struct let compare a b = a - b end ;; module M = Map.Make (IntOrd) ;; let m = M.add 1 \\\"a\\\" (M.add 2 \\\"b\\\" M.empty) ;; M.cardinal m\")")
|
||||
|
||||
;; ── Seq module (eager list-backed) ────────────────────────────
|
||||
(epoch 5190)
|
||||
(eval "(ocaml-run \"Seq.fold_left (+) 0 (Seq.map (fun x -> x * x) (Seq.of_list [1;2;3;4]))\")")
|
||||
(epoch 5191)
|
||||
(eval "(ocaml-run \"Seq.length (Seq.filter (fun x -> x mod 2 = 0) (Seq.of_list [1;2;3;4;5;6;7;8;9;10]))\")")
|
||||
(epoch 5192)
|
||||
(eval "(ocaml-run \"Seq.fold_left (+) 0 (Seq.init 5 (fun i -> i * 2))\")")
|
||||
(epoch 5193)
|
||||
(eval "(ocaml-run \"Seq.fold_left (+) 0 (Seq.unfold (fun n -> if n > 4 then None else Some (n, n + 1)) 1)\")")
|
||||
|
||||
EPOCHS
|
||||
|
||||
OUTPUT=$(timeout 360 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
|
||||
@@ -2274,6 +2284,12 @@ check 5180 "Set.Make dedupe sum" '9'
|
||||
check 5181 "Set.Make mem" 'true'
|
||||
check 5182 "Map.Make cardinal" '2'
|
||||
|
||||
# ── Seq module (eager list-backed) ──────────────────────────────
|
||||
check 5190 "Seq fold map squares" '30'
|
||||
check 5191 "Seq filter evens" '5'
|
||||
check 5192 "Seq init 5 i*2" '20'
|
||||
check 5193 "Seq unfold 1..4 sum" '10'
|
||||
|
||||
TOTAL=$((PASS + FAIL))
|
||||
if [ $FAIL -eq 0 ]; then
|
||||
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"
|
||||
|
||||
Reference in New Issue
Block a user