4 ms·
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
by tempodox 5y ago
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.
- choeger 5y agoNo. 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.
- tempodox 5y agoI 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.