Types - Manhunter07/MFL GitHub Wiki
Type in MFL act more like actual constraints rather than real types as known from other languages like Delphi, C++, C# or Java. MFL is not strongly-typed, either. Types in MFL are used for the following procedures:
- Constraining values passed as function arguments
- Constraining values stored in records or arrays passed as function arguments
- Being passed or stored as references
- Instantiating types via constructors
Values themselves are not actually typed in the sense of declared types. They are instead data-typed.
If no type is specified, no type check is performed. This is the equivalent of any
with no type arguments. There exists no requirement for typing anywhere in the language. It is mostly just there as an easy way to avoid passing unsupported values to functions.
Type groups
All types can be categorized into one (or, rarely some) of six distinct or partially-distincr groups:
- Sets of supported or unsupported other types (ie.
any
ornone
types) - Sets or ranges of supported values (ie.
enum
orrange
types) - Numeric types (ie.
integer
orrangeint
types) - Structured types (ie.
string
orarray
types) - Field types (ie.
record
orobject
types), a subset of structured types - Reference types
Some types (ie. rangeint
-declarations) combine multiple of these categories in one type.
Type declarations
See also: Type constructors
Type instances are created with a type name and a type constructor. The type constructor (not to be mistaken for constructors for types) may have a supported number of arguments and is used as part of the type declaration syntax. You declare types using the type
keyword. The type name is used for later reference. This must be followed by an equals sign and a type constructor with optional arguments. A general type declarration looks as follows:
[local ]type TypeName = typeconstructor([arg[, ...]])
Some type constructors require arguments, some support them and some do not allow them. Type construction arguments are defined in parentheses while named arguments are not supported here. If no arguments are to be used, parentheses may be omitted. The kind of the argument, its notation and its meaning depend on the type constructor used. Constants can be declared locally.
Examples
This is how an integer type is declared:
type MyInt = integer
If your integer is supposed to be dividable by not just 1
but also 2
(thus, is considered even), you must declare it this way:
type MyEvenInt = integer(2)
If that even integer shall be dividable also by 3
(thus, making it integer-dividable by 1
, 2
and 3
), you would have to declare it like this:
type MySuperInt = integer(2, 3)
Constructors
Main article: Constructors
Converters
Main article: Converters
Parameter types
See also: Function parameters
Type references
Main article: References