Data Model

How data is described and referenced in Fenl.

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.

Scalars

Scalar types include bool, number, and string.

Type

Examples

Description

bool

true, false

Booleans represent true or false

number

0, 1, -100, 10000, 0.0, -1.0, -100837.631

64-bit floating point numbers. When using a decimal a leading numeric character is required.

string

"hello", "hello \"john\""

Unicode strings. Strings are written with double-quotes. Double quotes may be escaped within the string.

Collections

Collection types include list and 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.

Type

Examples

Description

list<number>

list{}, list{1, 1, 10}

Lists represen an ordered sequence of 0 or more elements. They support lookup by index.

map<string, number>

map{},
map{"apple": 2, "ball": 5}

Elements in a map are key/value pairs. They support
lookup by key

Composites

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.

Type

Examples

Description

record<name: string, age: number>

{name: "john", age: 32}

A record is a composite type made up of 0 or (generally) more components. Each component is associated with a
field name.

Nullable Types

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.

Type

Examples

Description

string?

null, "", "john"

A string or the value null

record<name: string>?

null, {name: "john"}

A record or the value null. Note that if the record is non-null, the name field must be present, as its type is string.

Type Coercion

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 Promotion Rules

Type coercion will never produce an integer overflow or reduction in numeric precision. The coercion rules can be summarized with the following rules:

  1. Integers can be widened: i8 -> i16 -> i32 -> i64.
  2. Unsigned integers can be widened: u8 -> u16 -> u32 -> u64.
  3. Floating point numbers can be widened: f16 -> f32 -> f64.
  4. Unsigned integers can be promoted to the next wider integer u8 -> i16, u16 -> i32, u32 -> i64.
  5. All numbers may be converted to f64.
  6. Strings may be implicitly converted to timestamps by attempting to parse them as RFC3339 values. The timestamp will be null for strings that don't successfully parse.

Numeric Type Coercion Table

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.

i8i16i32i64u8u16u32u64f16f32f64
i8i8i16i32i64i16i32i64f64f16f32f64
i16i16i16i32i64i16i32i64f64f16f32f64
i32i32i32i32i64i16i32i64f64f16f32f64
i64i64i64i64i64i64i64i64f64f16f32f64
u8i16i16i16i64u8u16u32u64f16f32f64
u16i32i32i32i64u16u16u32u64f16f32f64
u32i64i64i64i64u32u32u32u64f16f32f64
u64f64f64f64f64u64u64u64u64f16f32f64
f16f16f16f16f16f16f16f16f16f16f32f64
f32f32f32f32f32f32f32f32f32f32f32f64
f64f64f64f64f64f64f64f64f64f64f64f64

️ Coercion to Floating-Point

Note that when u64 is combined with a signed type the result is f64. This is the only case where an operation between integers produces a floating-point value.


© Copyright 2021 Kaskada, Inc. All rights reserved. Privacy Policy

Kaskada products are protected by patents in the United States, and Kaskada is currently seeking protection internationally with pending applications.