[Grace-core] Brands

Timothy Jones tim at ecs.vuw.ac.nz
Sun Mar 2 14:41:39 PST 2014


I've implemented a proof of concept for brands on a branch of Minigrace. It adds
a hack the parser, implementing Michael's suggestion to add a unique method to
the type. I've done it this way because it's not yet clear how much power
custom annotations actually have.

If you annotate a type with the brand annotation, then it becomes a nominal
type. You can then mark a class as branded with that type.

    dialect "structural"

    type MyType is brand = {
        foo -> Number
    }

    class myClass.new is branded(MyType) {
        method foo -> Number { 1 }
    }

The typed dialect will then ensure that the nominal types match.

    method go(a : MyType) {}

    go(myClass.new)

    go(object {
        method foo -> Number { 1 }
    })

> Request TypeError: the expression `object {
>     method foo -> Number {
>         1
>     }
> }` of type '{ foo -> Number; }' does not satisfy the type of parameter 'a : MyType' in the method 'go'.

-- 
Tim


More information about the Grace-core mailing list