Skip to content

Sequence Constructors, Blocks can't be annotated with types #175

@apblack

Description

@apblack

We have a notation for a sequence constructor

[exp_1, exp_2, exp_3]

but we don't have a way of giving it a type. Do we want to add one? The "obvious" syntax would be

[exp_1, exp_2, exp_3]⟦ElementType⟧

For example,

["one", "two", "three", "four"]⟦String⟧

Note that the expressions inside the sequence constructor can be anything at all, so if we say "we should infer the types", then we are committing to inference everywhere — including inferring the result types of methods on arbitrary objects. If we do that, we have Haskell or ML, not Grace. (Is full type inference on an OO language even decidable?)

An alternative is adding type information to sequence constructors to say that the type of a sequence constructor is always Sequence⟦Unknown⟧. If you want to assert otherwise, you can convert it:

[exp_1, exp_2, exp_3] >> sequence⟦String⟧

which has type Sequence⟦String⟧ but will in general require a dynamic check on each element. Of course, a decent implementation (not minigrace) would get rid of the dynamic check in the case where the exp_n are statically known to be Strings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions