Fenl operates on typed values. Fenl's type system describes several different kinds of values.
Simple values such as the string "hello" or the integer 57 are scalar types. Zero or more scalar values of the same type may be part of a collection, such as a list, map, or set. Value types may be combined to create composite value types such as records.
Scalar types include
Booleans represent true or false
64-bit floating point numbers. When using a decimal a leading numeric character is required.
Unicode strings. Strings are written with double-quotes. Double quotes may be escaped within the string.
Collection types include
map. Each collection contains 0 or more elements of the same
type. A collection type describes the kind of collection, and the type of elements it contains.
Lists represen an ordered sequence of 0 or more elements. They support lookup by index.
Elements in a map are key/value pairs. They support
Composite types allow combining multiple different types into a single value. Records are unnamed - any two records with the same set of fields and values are considered equal. Fields within a record may have different types. Field names must start with a letter.
A record is a composite type made up of 0 or (generally) more components. Each component is associated with a
Value types may be either nullable or non-nullable. A nullable type allows any value from the base type as well as the value
null. Nullable types are distinguished by having a trailing question mark in the type description.
A string or the value
A record or the value
Fenl implicitly coerces numeric types when different kinds of numbers are combined. For example adding a 64-bit signed integer value to a 32-bit floating point value produces a 64-point floating point value.
Type coercion will never produce an integer overflow or reduction in numeric precision. The coercion rules can be summarized with the following rules:
- Integers can be widened:
i8 -> i16 -> i32 -> i64.
- Unsigned integers can be widened:
u8 -> u16 -> u32 -> u64.
- Floating point numbers can be widened:
f16 -> f32 -> f64.
- Unsigned integers can be promoted to the next wider integer
u16 -> i32,
u32 -> i64.
- All numbers may be converted to
- Strings may be implicitly converted to timestamps by attempting to parse them as RFC3339 values. The timestamp will be
nullfor strings that don't successfully parse.
When two numbers are used, Fenl attempts to promote them to a compatible type as the smallest type that both types may be converted to.
The following table shows the result of this promotion for pairs of numeric types.
️ Coercion to Floating-Point
Note that when
u64is combined with a signed type the result is
f64. This is the only case where an operation between integers produces a floating-point value.
Updated 3 months ago