home
menu
lock
Editing — Planned Type System
arrow_back
Back
add
Create a new page
delete
Delete this page
Editing
You must be authenticated for your changes to save. Styling with
Markdown
is supported.
# Passerine’s Type System Passerine has full support for algebraic data types. It’s structurally typed with support for type refinement at runtime. Passerine’s type system aims to be decidable and sound. # Core Algebraic Data Types ## Atoms Base types that can not be broken down. This includes: * Booleans * Numeric Tower * Strings ## Records product types over a set of fields: * Fields accessed via _indexing_ * Defined as: { f1: t1, f2: t2, …, fn: vn } * Constructed as: { f1: v1, f2: v2, … fn: vn } * A tuple is a record where each field is a number: \ ( v1, v2, …, vn ) * { a, b, c } is a valid record of type { a, b }. Extra fields are ignored. ## Unions sum types over a set of types: * Variants accessed via indexing * Defined as { Variant1 v1, Variant2 v2, …, Variantn vn } * Constructed as: Label::Variant v * Variants are _scoped_, so that, i.e. A::C != B::C. Variants are also proper types in their own right. ## Lists Homogenous growable array of items of a type: * Items accessed via indexing * Defined as [ type ] * Constructed as [ v1, v2, …, vn ] ## Labels Scoped namespaces to distinguish types with different semantics of the same structure. They must be defined with the type keyword: * Defined as Label <type or none if Label is Defined> * Constructed as Label value * Has an attached record for associated values, accessible via indexing. * If the namespace LabelA (the _type_) fills the structure of LabelB (the _trait_), LabelB::LabelA is a valid variant of LabelB.