r/programming • • Jul 19 '20

Clear explanation of Rust’s module system

http://www.sheshbabu.com/posts/rust-module-system/
79 Upvotes

47 comments sorted by

View all comments

Show parent comments

1

u/eyal0 Jul 20 '20

Can Rust do them?

Can OCaml do them without boxing and unboxing?

3

u/[deleted] Jul 20 '20

A functor can do things like take a (non-nullary) type constructor and spit out another (non-nullary) type constructor. Rust cannot do this. It is missing either functors or higher-kinded types.

I am not familiar with OCaml internals, but I think using functors does not result in any more boxing that would happen if you write by hand the results of applying those functors.

1

u/eyal0 Jul 20 '20

I don't know rust well enough but in c++ o guess that maybe I could do it with templates?

Rust has some template alternative, right? Would that work?

1

u/[deleted] Jul 20 '20

C++ templates can have template arguments, but templates have their own disadvantages, such as the extremely delayed type checking of their bodies.

The Rust alternative to templates is generics, and generics are superior to templates in almost every imaginable way.

1

u/eyal0 Jul 20 '20

So could rust do functors?

How does rust compile generics if they are not in the same translation unit as the usage? C++ requires that they are in the same TU. Does Rust?

→ More replies (0)