Closed
Description
Exporting a tag type but not the constructors for it is a simple way to construct abstract data types. (This is how it is done in Haskell.) This works in rust as well, but only for tags with multiple constructors. If the tag has only a single constructor, * will see through it regardless of the visibility of the constructor.
Example
mod ctr { export ctr; export new; export inc; export print; tag ctr { mkCtr(int); } fn new(i: int) -> ctr { mkCtr(i) } fn inc(c: ctr) -> ctr { mkCtr(*c + 1) } fn print(c: ctr) { log_err *c; } } fn main() { let c = ctr::new(42); ctr::print(c); let c2 = ctr::inc(c); ctr::print(c2); log_err *c2; }
Part of the problem might be that dereference on single element tags isn't a particularly principled idea to begin with, but it is undeniably convenient.