ocaml: phase 6 Bool module + Option.equal/Option.compare (+5 tests, 584 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 50s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 50s
Bool module: equal a b = a = b compare a b = 0 if equal, 1 if a, -1 if b (false < true) to_string 'true' / 'false' of_string s = s = 'true' not_ wraps host not to_int true=1, false=0 Option additions (take eq/cmp parameter for the inner value): equal eq a b None=None, otherwise eq the inner values compare cmp a b None < Some _; otherwise cmp inner Option.equal (=) (Some 1) (Some 1) = true Option.equal (=) (Some 1) None = false Option.compare compare (Some 5) (Some 3) = 1
This commit is contained in:
@@ -321,6 +321,18 @@
|
||||
| None -> Error none_v
|
||||
| Some x -> Ok x
|
||||
|
||||
let equal eq a b =
|
||||
match a with
|
||||
| None -> (match b with None -> true | Some _ -> false)
|
||||
| Some x ->
|
||||
(match b with None -> false | Some y -> eq x y)
|
||||
|
||||
let compare cmp a b =
|
||||
match a with
|
||||
| None -> (match b with None -> 0 | Some _ -> -1)
|
||||
| Some x ->
|
||||
(match b with None -> 1 | Some y -> cmp x y)
|
||||
|
||||
let some x = Some x
|
||||
let none = None
|
||||
end ;;
|
||||
@@ -464,6 +476,18 @@
|
||||
let sub s i n = String.sub s i n
|
||||
end ;;
|
||||
|
||||
module Bool = struct
|
||||
let equal a b = a = b
|
||||
let compare a b =
|
||||
if a = b then 0
|
||||
else if a then 1
|
||||
else -1
|
||||
let to_string b = if b then \"true\" else \"false\"
|
||||
let of_string s = s = \"true\"
|
||||
let not_ b = not b
|
||||
let to_int b = if b then 1 else 0
|
||||
end ;;
|
||||
|
||||
module Char = struct
|
||||
let code c = _char_code c
|
||||
let chr n = _char_chr n
|
||||
|
||||
@@ -1448,6 +1448,18 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 5202)
|
||||
(eval "(ocaml-run \"String.cat \\\"hello \\\" \\\"world\\\"\")")
|
||||
|
||||
;; ── Bool module + Option.equal/compare ───────────────────────
|
||||
(epoch 5210)
|
||||
(eval "(ocaml-run \"Bool.to_string true ^ \\\"-\\\" ^ Bool.to_string false\")")
|
||||
(epoch 5211)
|
||||
(eval "(ocaml-run \"Bool.compare true false\")")
|
||||
(epoch 5212)
|
||||
(eval "(ocaml-run \"Option.equal (=) (Some 1) (Some 1)\")")
|
||||
(epoch 5213)
|
||||
(eval "(ocaml-run \"Option.equal (=) (Some 1) None\")")
|
||||
(epoch 5214)
|
||||
(eval "(ocaml-run \"Option.compare compare (Some 5) (Some 3)\")")
|
||||
|
||||
EPOCHS
|
||||
|
||||
OUTPUT=$(timeout 360 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
|
||||
@@ -2303,6 +2315,13 @@ check 5200 "String.equal abc abc" 'true'
|
||||
check 5201 "String.compare banana apple" '1'
|
||||
check 5202 "String.cat hello world" '"hello world"'
|
||||
|
||||
# ── Bool module + Option.equal/compare ─────────────────────────
|
||||
check 5210 "Bool.to_string true/false" '"true-false"'
|
||||
check 5211 "Bool.compare true false" '1'
|
||||
check 5212 "Option.equal Some 1 Some 1" 'true'
|
||||
check 5213 "Option.equal Some 1 None" 'false'
|
||||
check 5214 "Option.compare Some 5 Some 3" '1'
|
||||
|
||||
TOTAL=$((PASS + FAIL))
|
||||
if [ $FAIL -eq 0 ]; then
|
||||
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"
|
||||
|
||||
@@ -407,6 +407,12 @@ _Newest first._
|
||||
binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree *
|
||||
'a tree`) with insert + in-order traversal. Tests parametric ADT,
|
||||
recursive match, List.append, List.fold_left.
|
||||
- 2026-05-09 Phase 6 — Bool module + Option.equal / Option.compare
|
||||
(+5 tests, 584 total). Bool: equal, compare (false < true via if
|
||||
ladder), to_string, of_string, not_, to_int. Option additions
|
||||
take an `eq` or `cmp` parameter for the inner-value check, mirroring
|
||||
real OCaml's signature: `Option.equal eq a b`, `Option.compare cmp
|
||||
a b`. None < Some _ for compare.
|
||||
- 2026-05-09 Phase 5.1 — bag.ml baseline + String.equal/compare/cat/
|
||||
empty (+3 tests, 579 total). bag.ml: split a sentence on spaces,
|
||||
count word frequency in a Hashtbl, return the maximum count.
|
||||
|
||||
Reference in New Issue
Block a user