Live data from Hacker News

A new C++ back end for ocamlc

github.com

11–20 of 24 posts

Re: A new C++ back end for ocamlc

#11
> Using these more sophisticated data structures, g++ is able to compute the prime numbers below 10000 in only 8 seconds, using a modest 3.1 GiB of memory.

Finally, I can get some primes on my laptop!

Re: A new C++ back end for ocamlc

#14
post #10

[flagged]

Might have missed the joke here. This isn't a traditional C++ backend; it's a C++ Template Metaprogramming backend. The code isn't meant to be run—it’s meant to be compiled. The "output" you see is actually just a compiler error message because the program forces the compiler to calculate primes during type checking. The "runtime performance" the author mentioned is actually just how long g++ takes to crash your ram.

Re: A new C++ back end for ocamlc

#20
post #19

> which produces primes.cpp, containing your program translated to idiomatic, readable C++ code: As a C++ enjoyer I can confirm this is some excellent idiomatic, readable C++ code.

Most of it yes, but what about:

    typedef I::val) != (I::val))> res;
    };
There is some top class wizardry going on there! I don’t think I’ve ever used conditions in a type definition in C++ :)

Update:

Ah, alright - so that evaluation logic is part of the template, not the code that eventually compiles.

It’s basically offloading some of the higher level language compiler logic to the templating engine. Honestly might be a better time investment than spending more time writing this in the parser.

Now I’m sort of intrigued and inspired to use C++ as a lowering target for elevate (a compiler framework I’ve been working on).

Post reply on HN