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

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:
2026-05-09 06:26:33 +00:00
parent ddd1e40d00
commit 4d32c80a99
3 changed files with 49 additions and 0 deletions

View File

@@ -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