esumii / min-caml Goto Github PK
View Code? Open in Web Editor NEWmoved from https://sourceforge.net/p/min-caml/code/
License: Other
moved from https://sourceforge.net/p/min-caml/code/
License: Other
The readme states:
As in ordinary ML, MinCaml infers the types of variables and functions even if no types are given in the program. This functionality is called type inference. It is very useful in particular for programs with polymorphic and higher-order functions.
But generalization and instantiation are missing from the type system, so it's not actually implementing polymorphic functions at all. For example, this fails:
let rec f y = 0 in
let _ = f 0 in
let _ = f true in
print_int 0
with:
Fatal error: exception Typing.Error(_, 2, 1)
If this is intended, it would be good to specify that the type system does actually not support Hindley-Milner type inference.
In virtual.ml
, an entry in floating-point constant table is reused if they equate by =
. Unfortunately, =
does not distinguish the sign of zero, so MinCaml wrongly convert -0.0
to 0.0
(or vice versa) if both 0.0
and -0.0
are used in the program.
For example, the following code prints 0
on OCaml, but it will print 1
on MinCaml (I haven't managed to run the generated code, but the constant table in the assembly contains only 0.0
).
let rec f x = x /. 0.0 = x /. -0.0 in
if f (cos 0.0) then print_int 1 else print_int 0
In OCaml, there is Float.sign_bit
to examine the sign of zero, but it is a relatively new feature (since 4.08.0). Another solution is d = d' && 1.0 /. d = 1.0 /. d'
.
the example ack.ml under floder test:
let rec ack x y =
if x <= 0 then y + 1 else
if y <= 0 then ack (x - 1) 1 else
ack (x - 1) (ack x (y - 1)) in
print_int (ack 3 10)
if I change the line
print_int (ack 3 10)
to this:
print_int (ack 3 1.23)
then make,got error:
Fatal error:exception Typing.Error(_,2,3)
I search the sorce,can't find info of Typing.Error,or Fatal.so how min-caml catch the type error?The ocaml compiler display in other way:
Error:this expression has type float but an expression was expected of type int
so where is the info
Fatal error:exception Typing.Error(_,2,3)
from?Thanks!
ビルドシステムを dune に対応させる予定とかってありますかね.(ちょっとやってみようとしたけど,結構な改造が必要そう?)
Repro:
let rec f _ = 42 in
print_int (f f)
Error:
uninstantiated type variable detected; assuming int
Fatal error: exception Typing.Error(_, 2, _)
It looks that type inference cannot infer the type of a function which is called with itself as argument such as f
in above. But I'm not sure that this is a limitation of type inference. So I created this issue.
Hi! MinCaml is such a wonderful project, I keep coming back to it.
Would you consider adding a license to the project (or releasing it into the public domain, whichever you prefer)?
That would make it easier to contribute / fork and experiment / derive projects from the existing code: https://choosealicense.com/no-permission/
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.