ocaml: phase 6 List.combine/split/iter2/fold_left2/map2 (+4, 367 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 30s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 30s
Mechanical pair-walk OCaml implementations. failwith on length mismatch matches Stdlib semantics. List module now covers 30+ functions.
This commit is contained in:
@@ -157,6 +157,47 @@
|
||||
end
|
||||
|
||||
let stable_sort = sort
|
||||
|
||||
let rec combine xs ys =
|
||||
match xs with
|
||||
| [] -> (match ys with
|
||||
| [] -> []
|
||||
| _ -> failwith \"List.combine: unequal lengths\")
|
||||
| hx :: tx ->
|
||||
match ys with
|
||||
| [] -> failwith \"List.combine: unequal lengths\"
|
||||
| hy :: ty -> (hx, hy) :: combine tx ty
|
||||
|
||||
let rec split lst =
|
||||
match lst with
|
||||
| [] -> ([], [])
|
||||
| (a, b) :: t ->
|
||||
(match split t with
|
||||
| (xs, ys) -> (a :: xs, b :: ys))
|
||||
|
||||
let rec fold_left2 f acc xs ys =
|
||||
match xs with
|
||||
| [] -> (match ys with [] -> acc | _ -> failwith \"List.fold_left2: unequal\")
|
||||
| hx :: tx ->
|
||||
match ys with
|
||||
| [] -> failwith \"List.fold_left2: unequal\"
|
||||
| hy :: ty -> fold_left2 f (f acc hx hy) tx ty
|
||||
|
||||
let rec iter2 f xs ys =
|
||||
match xs with
|
||||
| [] -> (match ys with [] -> () | _ -> failwith \"List.iter2: unequal\")
|
||||
| hx :: tx ->
|
||||
match ys with
|
||||
| [] -> failwith \"List.iter2: unequal\"
|
||||
| hy :: ty -> f hx hy; iter2 f tx ty
|
||||
|
||||
let rec map2 f xs ys =
|
||||
match xs with
|
||||
| [] -> (match ys with [] -> [] | _ -> failwith \"List.map2: unequal\")
|
||||
| hx :: tx ->
|
||||
match ys with
|
||||
| [] -> failwith \"List.map2: unequal\"
|
||||
| hy :: ty -> f hx hy :: map2 f tx ty
|
||||
end ;;
|
||||
|
||||
module Option = struct
|
||||
|
||||
@@ -900,6 +900,16 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 2105)
|
||||
(eval "(ocaml-type-of-program \"let rec fact n = if n = 0 then 1 else n * fact (n - 1);; fact 5\")")
|
||||
|
||||
;; ── More List functions: combine/split/iter2/fold_left2/map2 ──
|
||||
(epoch 2200)
|
||||
(eval "(ocaml-run \"List.combine [1;2;3] [\\\"a\\\";\\\"b\\\";\\\"c\\\"]\")")
|
||||
(epoch 2201)
|
||||
(eval "(ocaml-run \"List.split [(1,\\\"a\\\");(2,\\\"b\\\")]\")")
|
||||
(epoch 2202)
|
||||
(eval "(ocaml-run \"List.fold_left2 (fun a b c -> a + b + c) 0 [1;2;3] [10;20;30]\")")
|
||||
(epoch 2203)
|
||||
(eval "(ocaml-run \"List.map2 (fun a b -> a + b) [1;2;3] [10;20;30]\")")
|
||||
|
||||
EPOCHS
|
||||
|
||||
OUTPUT=$(timeout 180 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
|
||||
@@ -1423,6 +1433,12 @@ check 2103 "shape -> Int" '"shape -> Int"'
|
||||
check 2104 "program x+y" '"Int"'
|
||||
check 2105 "program fact 5" '"Int"'
|
||||
|
||||
# ── More List functions ─────────────────────────────────────────
|
||||
check 2200 "List.combine" '("tuple" 3 "c")'
|
||||
check 2201 "List.split" '("tuple" (1 2) ("a" "b"))'
|
||||
check 2202 "List.fold_left2" '66'
|
||||
check 2203 "List.map2" '(11 22 33)'
|
||||
|
||||
TOTAL=$((PASS + FAIL))
|
||||
if [ $FAIL -eq 0 ]; then
|
||||
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"
|
||||
|
||||
Reference in New Issue
Block a user