|
![]() |
||||||||||||||
Tuple TutorialTuple Type CheckingIf T1 is a tuple type with N elements, and T2 is another tuple type with K elements (0<K<N), and for each i (0<i<=K) the type of i-th element of T1 is the same as the type of i-th element of T2, then we say that T1 is subtype of T2. In Wafl, if a function is defined for argument of a tuple type, then it is applicable to subtypes of that type, too. That same rule is used with selectors. In the following example, a function sums first and second elements of a given tuple. The function is applicable to subtypes, too. (Of course, first and second elements have to have a same type). Source code:{# {# 1,2 #}->f(), {# 1,2,3 #}->f(), {# 1,2,'a string' #}->f(), {# 1.2,2.4,'a string' #}->f(), {# 'a','b',1.2,2.4,'a string' #}->f() #} where{ f(t) = t.1 + t.2; } Result:{# 3, 3, 3, 3.600000, "ab" #}
|
|
||||||||||||||
© 2006 Saša Malkov | |||||||||||||||