Skip to content

Dereference on single element tags ignores visibility of constructor #818

Closed
@msullivan

Description

@msullivan

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions