Parametric polymorphism: Difference between revisions

m
Line 248:
#fix general_type_fixer 1
 
binary_tree_of "node_typenode-type" = ("node_typenode-type",(binary_tree_of "node_typenode-type")%Z)%drWZwlwAZ
</lang>
(The %Z type operator constructs a "maybe" type", i.e., the free union of its operand type
with the null value. Others shown above are standard stack manipulation primitives, e.g. d (dup) and w (swap), used to build the type expression tree.) At the other extreme, one may construct an equivalent parameterized type in
point-free form.
<lang Ursala>
binary_tree_of = %-hhhhWZAZ
</lang>
A mapping combinator over this type can be defined aswith shown.pattern matching like this
<lang Ursala>
binary_tree_map "f" = ~&a^& ^A/"f"@an ~&amPfamPWB
</lang>
or in point free form like this.
<lang Ursala>
binary_tree_map = ~&a^&+ ^A\~&amPfamPWB+ @an
</lang>
Here is a test program
Line 274 ⟶ 278:
Type signatures are not associated with function declarations, but
have uses in the other contexts such as assertions and compiler directives
(e.g., #cast). Here is the output:.
<pre>
'foofoo': ('barbar': (),'bazbaz': ())
Anonymous user