Disjunction Types
MUFL defines a type expression <type1> || <type2>
to mean a value of either <type1>
or <type2>
.
Nullable Types
MUFL defines a type expression <type>+
to represent the special disjunction <type> || NIL
.
This is why boolean in MUFL is
true+
–true
is a one-element type and nullable-true is the same as ‘true or null’, that is, boolean.
Value Sets
MUFL defines a value set (sometimes thought of as an enumerated type) as a type expression of the form <a,b,c, ... >
, where a, b, and c are strings. Values inside value sets can only be strings. Value sets can be assigned to strings, but assinging a string to a variable declared as a value set is an error.
metadef t_values: <$good, $bad, $soso>.
MyValue is t_values = $good. // OK
HisValue is t_values = $awful. // Compile error because $awful is not part of the value set 't_values'
Constituent Types
Given a type X
, which is reduceable (for example, a function), it is sometimes convenient to declare a type that represents the type of the argument of function of type X
, or the type of the return value of the function of type X
. We call them constituent types because they are used as building blocks to construct more complex types.
A type can be declared to be a constituent type of a complex type using the /
syntax with the name of the constituent element, for example /reducer
or /product
.
/reducer
refers to the argument type of a complex type (e.g. a function)
/product
refers to the result type of a complex type
For example:
metadef X: (int->str->str). // function of two parameters '(int, str)' returning a 'str'
metadef X_arg1: X/reducer. // resolves to 'int'
metadef X_arg2: X/product/reducer. // resoves to 'str' - second argument
metadef X_ret: X/product/product. // resolves to 'str' - return type
Type-of-Variable Expression
Given a variable defined in the current scope, it is often convenient to declare a variable of the same type. This declaration uses the ?
syntax:
A is int(,) = (1,2,3).
B is ?A = (5,6,7).
metadef B_element_type: ?B/reducer. // will derive `int`