ocaml: phase 5 HM with user type declarations (+6 tests, 363 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 26s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 26s
ocaml-hm-ctors is now a mutable list cell; user type-defs register
their constructors via ocaml-hm-register-type-def!. New
ocaml-type-of-program processes top-level decls in order:
- type-def: register ctors with the scheme inferred from PARAMS+CTORS
- def/def-rec: generalize and bind in the type env
- exception-def: no-op for typing
- expr: return inferred type
Examples:
type color = Red | Green | Blue;; Red : color
type shape = Circle of int | Square of int;;
let area s = match s with
| Circle r -> r * r
| Square s -> s * s;;
area : shape -> Int
Caveat: ctor arg types parsed as raw source strings; registry defaults
to int for any single-arg ctor. Proper type-source parsing pending.
This commit is contained in:
@@ -886,6 +886,20 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 2005)
|
||||
(eval "(ocaml-type-of \"let rec sum lst = match lst with | [] -> 0 | h :: t -> h + sum t in sum [1; 2; 3]\")")
|
||||
|
||||
;; ── HM with user type declarations ─────────────────────────────
|
||||
(epoch 2100)
|
||||
(eval "(ocaml-type-of-program \"type color = Red | Green | Blue;; Red\")")
|
||||
(epoch 2101)
|
||||
(eval "(ocaml-type-of-program \"type shape = Circle of int | Square of int;; Circle 5\")")
|
||||
(epoch 2102)
|
||||
(eval "(ocaml-type-of-program \"type color = Red | Green;; let c = Red;; c\")")
|
||||
(epoch 2103)
|
||||
(eval "(ocaml-type-of-program \"type shape = Circle of int | Square of int;; let area s = match s with | Circle r -> r * r | Square s -> s * s;; area\")")
|
||||
(epoch 2104)
|
||||
(eval "(ocaml-type-of-program \"let x = 1;; let y = 2;; x + y\")")
|
||||
(epoch 2105)
|
||||
(eval "(ocaml-type-of-program \"let rec fact n = if n = 0 then 1 else n * fact (n - 1);; fact 5\")")
|
||||
|
||||
EPOCHS
|
||||
|
||||
OUTPUT=$(timeout 180 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
|
||||
@@ -1401,6 +1415,14 @@ check 2003 "type 1::list" '"Int list"'
|
||||
check 2004 "type [1] @ [2;3]" '"Int list"'
|
||||
check 2005 "type sum" '"Int"'
|
||||
|
||||
# ── HM with user type-defs ──────────────────────────────────────
|
||||
check 2100 "user type Red : color" '"color"'
|
||||
check 2101 "user type Circle 5 : shape" '"shape"'
|
||||
check 2102 "let c = Red; c" '"color"'
|
||||
check 2103 "shape -> Int" '"shape -> Int"'
|
||||
check 2104 "program x+y" '"Int"'
|
||||
check 2105 "program fact 5" '"Int"'
|
||||
|
||||
TOTAL=$((PASS + FAIL))
|
||||
if [ $FAIL -eq 0 ]; then
|
||||
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"
|
||||
|
||||
Reference in New Issue
Block a user