Hacker News new | ask | show | jobs
by shakna 3234 days ago
C++ is in this boat now.

Most of the time I'd recommend the new type-safe union std::variant, but std::any is there.

It is kinda a static type, but as a container-type of anything in the type system, it may as well be a dynamic type.

---

> All that survived into Common Lisp but I am not up on the current state of lisp implementations and have no idea if people bother to take advantage of it any more.

Typed Racket uses the early guard theories from CL [1], and it does have an optimiser [2], though it has some quirks.

And though I can't find it now, there was a fairly recent research paper on using a macro system to static type check at compile-time and optimise for Scheme. But, I should point out that Scheme doesn't need it for optimisation - compiling Scheme to C is easy, and easy to make the result fast. Its more about safety.

And there's always Shen which uses sequent calculus [3] for their optional static type system.

[0] https://docs.racket-lang.org/ts-guide/

[1] http://www.cs.utexas.edu/users/boyer/ftp/diss/akers.pdf

[2] https://docs.racket-lang.org/ts-guide/optimization.html

[3] http://shenlanguage.org/learn-shen/index.html#10%20Sequent%2...

1 comments

> Most of the time I'd recommend the new type-safe union std::variant

Neither g++ 7 nor Clang/LLVM 4.0.1 support std::variant yet :-(. We started a new (blank buffer) codebase earlier this year and decided to use C++17 as the implementation language, which has exposed us to the gaps...which are surprisingly few! But sadly this is one of them.

> Neither g++ 7

Eh? I've been using it a hell of a lot!

std::variant is listed on GCC 7's page [0], and I know that is there in at least 7.1

I don't use clang much, but they list it as supported [1], and I believe the patch [2] landed in 5.0

[0] https://gcc.gnu.org/gcc-7/changes.html

[1] https://libcxx.llvm.org/cxx1z_status.html

[2] https://reviews.llvm.org/rL288547

Hmm, have to check include paths again!
So I glanced over this, and found that std::variant is in libc++, as you would expect, but in some cases, when you get a nice modern compiler, you might not end up with it linked to a nice modern stdlib.

So maybe some sort of mis-match got in your way.

Anyways, here's hoping you get to use C++17 in its full glory!