Quick StartTryGuideAPICommunityBlogGitHub
Search

Integer & FloatSuggest an edit

Integers

32-bits, truncated when necessary. Reason provides the usual operations on them: +, -, *, /, etc.

Usage

See the Int32 module in the standard library. For JS compilation, see Js.Int.

Tips & Tricks

Careful when you bind to JavaScript numbers! Long ones might be truncated. Bind JS number as float instead.

Floats

Float requires other operators: +., -., *., /., etc. Like 0.5 +. 0.6.

Usage

There's no Float module in the current standard library. For JS compilation, see Js.Float.

Design Decisions

"Why the heck can't I just use an overloaded + for both int and float? Why is it that each time I find a performant language with great types and interop and community, I find these kind of flaws?"

There, there. Polymorphic operators, under the current type system, would need to be hard-coded into the compiler. The physical polymorphic equal, ==, is such an operator; + and the rest aren't. Improvements are under way to make them work as desired. In the meantime, let's keep shipping =).

Additionally, floats are rather special in Reason/OCaml native. Check here if you're interested in learning some rather interesting optimizations!