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
- Being passed as references
- Instantiating types via constructors
Values themselves are not actually typed in the sense of declared types. They are instead data-typed.
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