-
Notifications
You must be signed in to change notification settings - Fork 1
Description
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.