Type Syntax Sugar
Even though types such as array, choice, function types, are mapped to Fuzion features, it could improve readability and usability a lot to have special syntax for declaration of these types and their instances.
|
is
type
|
Feature | Type Declaration | value syntax sugar | comment | |
|---|---|---|---|---|---|
| verbose | syntax sugar | ||||
| sequence, list or array | Sequence |
Sequence A |
[T] |
[a,b,c][] |
A value [a,b,c] is an instance
of array T (that can be assigned to
type Sequence T), while type [A] is
equivalent to Sequence T. The type of a sequence
value is inferred from the target it is assigned to, or, if the target
does not have a declared type, from the first element in the sequence
([void] for an empty sequence).
|
| dictionary, map | Map |
Map A B |
[A => B] |
[a1 => b1,
|
A map value is of type ordered_map, the elements must inherit ordered. |
| function or lambda | Function |
Function R A BFunction R AFunction R |
(A,B) -> RA,B -> R(A) -> RA -> R() -> R
|
(a,b) -> f a ba,b -> f a b(a) -> f aa -> f a() -> f const
|
A lambda value must be assigned to a field of a function type. |
| tagged union | choice |
choice A B C |
A | B | C |
a |
A value a of type A will be converted to a
choice type A | B | C implicitly in an assignment to a field
whose type is the choice type. |
| tuple | tuple |
tuple A B C |
(A, B, C) |
(a, b, c)()
|
Note that (a) is _not_ a one-tuple. The type
of () is unit, which is an heir
of tuple.Tuple syntax is also used for destructuring as in (x, y) := point.
|