ocaml: phase 1/5/6 float arithmetic +./-./*./. (+5 tests, 372 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 27s

Tokenizer: +. -. *. /. (with -. avoiding clash with negative float
literals). Parser table places dotted ops at int-precedence levels.
Eval routes to host SX +/-/*//. HM types them Float->Float->Float;
literal floats now infer as Float (was Int).

OCaml-style 1.5 +. 2.5 : Float works end-to-end through tokenize +
parse + eval + infer.
This commit is contained in:
2026-05-08 13:55:04 +00:00
parent 16df48ff74
commit ee002f2e02
6 changed files with 53 additions and 1 deletions

View File

@@ -37,9 +37,15 @@
"true" (hm-monotype (hm-bool))
"false" (hm-monotype (hm-bool))}))))
;; Float type isn't in the kit; use a named ctor.
(define ocaml-hm-float (fn () (hm-con "Float" (list))))
(define ocaml-hm-builtin-env
(fn ()
(let ((int-int-int (hm-arrow (hm-int) (hm-arrow (hm-int) (hm-int))))
(float-float-float
(hm-arrow (ocaml-hm-float)
(hm-arrow (ocaml-hm-float) (ocaml-hm-float))))
(int-int-bool (hm-arrow (hm-int) (hm-arrow (hm-int) (hm-bool))))
(bool-bool-bool (hm-arrow (hm-bool) (hm-arrow (hm-bool) (hm-bool))))
(str-str-str (hm-arrow (hm-string) (hm-arrow (hm-string) (hm-string))))
@@ -66,6 +72,10 @@
"-" (hm-monotype int-int-int)
"*" (hm-monotype int-int-int)
"/" (hm-monotype int-int-int)
"+." (hm-monotype float-float-float)
"-." (hm-monotype float-float-float)
"*." (hm-monotype float-float-float)
"/." (hm-monotype float-float-float)
"mod" (hm-monotype int-int-int)
"%" (hm-monotype int-int-int)
"**" (hm-monotype int-int-int)
@@ -444,7 +454,7 @@
(else
{:subst {} :type (hm-fresh-tv counter)}))))
((= tag "int") {:subst {} :type (hm-int)})
((= tag "float") {:subst {} :type (hm-int)}) ;; treat float as int for now
((= tag "float") {:subst {} :type (ocaml-hm-float)})
((= tag "string") {:subst {} :type (hm-string)})
((= tag "char") {:subst {} :type (hm-string)})
((= tag "bool") {:subst {} :type (hm-bool)})
@@ -572,5 +582,6 @@
(let ((a (ocaml-hm-format-type (nth args 0)))
(b (ocaml-hm-format-type (nth args 1))))
(str "(" a ", " b ") result")))
((= head "Float") "Float")
(else head))))
(else (str t)))))