News for hackers. Stuff that matters.
Re:Sayonara, C++, and Hello to Rust by tempodox on Tuesday December 07, 2021 @06:34AM (#29471362)
Re OCaml: For what a C++ template does, you'd use a parameterized module (“functor”), not a macro. The OCaml macro equivalent would be a PPX rewriter, which is a rather heavy-handed approach to metaprogramming.
Re:Sayonara, C++, and Hello to Rust by choeger on Tuesday December 07, 2021 @11:04AM (#29474030)
No. An ML-style functor is well-designed and can be type checked at the site of definition. If C++ had functors I would be very happy, but functors are not "zero cost" abstractions..., maybe they can be in a compiler like MLton, though.
Re:Sayonara, C++, and Hello to Rust by tempodox on Thursday December 09, 2021 @04:37AM (#29495474)
I was referring to the use case, not the implementation details. ML-style functors may not be zero-cost abstractions, but they are a way to implement polymorphism, just like C++ templates. You may be able to achieve that with a PPX rewriter, but I'd rather use a functor.