PPP Exercises: Type Operators
Another construct in TL are type operators. They are used syntactically like functions. To show this similarity, we'll start with a short demonstration. Note that all the definitions of 'f' mean the same just like the definitions of 'T'. Which syntax you choose, is a question of your own programming habits.
Demo: Functions & Type Operators
let f(i :Int) :Int = i;
let f(i :Int) = i;
let f = fun(i :Int) :Int i;
let f = fun(i :Int) i;
Let T(I <:Ok) <:Ok = I;
Let T(I <:Ok) = I;
Let T = Oper(I <:Ok) <:Ok I;
Let T = Oper(I <:Ok) I;
Note: Array is also a type operator!
Exercise: Functions & Type Operators
- Write a function 'f' that gets an integer and returns a tuple with
this integer.
- Write a type operator 'T' that gets a type and returns a tuple type
with one field of this type.
- Test 'f' and 'T' by creating a value using the function
'f' of a type that is generated by applying 'T'.
Why, do you think, are the type operators in TL a useful concept?
Ulrike Steffens, 1994