Hello dear people reading this!
Today, I am overly excited to announce one of the greatest and simplest tool, that will fix the biggest of all OCaml flaws.
Consider Javascript:
$ node
Welcome to Node.js v22.14.0.
Type ".help" for more information.
> 1 + 3.5
4.5
Simple and elegant, don’t we all agree?
Now, the same with OCaml:
$ ocaml
OCaml version 5.3.0
Enter #help;; for help.
# 1 + 3.5 ;;
Error: The constant 3.5 has type float but an expression was expected of type
int
What does this even mean?
The PPX that I lovingly share with you all is ppx_untype
. It finally fully removes the OCaml type system that has plagued it since its inception.
The PPX can be used very simply. Add it to your opam switch:
$ opam pin add ppx_untype https://github.com/panglesd/ppx_untype.git\#main
and then add it to your dune
(or other build system) file:
(...
(preprocess (pps ppx_untype))
...)
And you can now enjoy OCaml!
$ cat bin.main.ml
let () = print_float (1 + 3.5)
$ dune exec bin/main.exe
3.47922429887e-310
Pros:
- All programs that was working before, still works.
- Blazingly fast!
- Finally integers and floats can be added.
- All warnings are also removed.
Cons:
- None (apart from some unexpected behaviour at runtime)
24 Likes
I see that a cheat engine for roguetype has been published on the very first day of the release!
11 Likes
Thank you, this looks lovely!
Once this has been proved useful, and although I do not see how this
could be not happening, I would like to encourage you to go one step
further in this direction by opening a PR to the compiler itself to
basically get rid of its typiing/
subdirectory, which will, by your
magic, contain only dead code.
How many headaches will we save…
Very nice! I often use the ocaml
REPL as a calculator.
It’s totally improductive because of the number of type errors I make but remains faster than using a calculator app with hidden state or another language that is not as hardwired in my brain as OCaml is.
So I actually contemplated more than once adding a Down.calculator ()
mode that would do exactly that:
- Redefine integer operators to work on floats (easy)
- Transforms integer literals into floating point ones (unclear).
Just never got the time to get to it yet. No joke. (PR’s welcome as they say)
:–)
1 Like
bc
is old but it still a good friend for that (in my opinion).
1 Like
I just wanted to clarify that ppx_untype
allows much more than computing with ints and floats. You can easily add functions together!
$ cat bin/main.ml
let () =
let x = (fun x -> x + 1) + (fun x -> x - 1) in
print_int x
$ dune exec bin/main.exe
109934791872403
7 Likes
Very nice. I’m so sick of warnings!