ocaml: phase 5.1 safe_div.ml baseline + Result.equal/compare/iter_error (+3 tests, 592 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
safe_div.ml: integer division returning Result. Sum-safe folds pairs,
skipping the Error branches.
[(10,2); (20,4); (30,0); (50,5)] -> 5 + 5 + 0 + 10 = 20
Result module additions (mirroring real OCaml's signatures):
equal eq_ok eq_err a b
compare cmp_ok cmp_err a b Ok < Error (i.e. Ok x compared to
Error e returns -1)
iter_error f r
Result.equal (=) (=) (Ok 1) (Ok 1) = true
Result.compare compare compare (Ok 5) (Ok 3) = 1
Result.compare compare compare (Ok 1) (Error _) = -1
30 baseline programs total.
This commit is contained in:
@@ -410,6 +410,25 @@
|
||||
match r with
|
||||
| Ok x -> ok_f x
|
||||
| Error e -> err_f e
|
||||
|
||||
let equal eq_ok eq_err a b =
|
||||
match a with
|
||||
| Ok x ->
|
||||
(match b with Ok y -> eq_ok x y | Error _ -> false)
|
||||
| Error e ->
|
||||
(match b with Ok _ -> false | Error e2 -> eq_err e e2)
|
||||
|
||||
let compare cmp_ok cmp_err a b =
|
||||
match a with
|
||||
| Ok x ->
|
||||
(match b with Ok y -> cmp_ok x y | Error _ -> -1)
|
||||
| Error e ->
|
||||
(match b with Ok _ -> 1 | Error e2 -> cmp_err e e2)
|
||||
|
||||
let iter_error f r =
|
||||
match r with
|
||||
| Ok _ -> ()
|
||||
| Error e -> f e
|
||||
end ;;
|
||||
|
||||
module String = struct
|
||||
|
||||
Reference in New Issue
Block a user