Playground Documentation Challenges Full Docs

Types

Declaring and using types in Formall

Overview

Formall is a strongly-typed language. Every expression has a type, and type mismatches are caught at parse time. Types are declared using the type(...) command.

type(typeName1, typeName2, ...)
typeName1, …
Names of new primary types; the other forms of type (enumerations, subtypes, type variables) are on the type page.

Basic examples

Primary Types

Primary types are the basic building blocks. They represent sets of values (like booleans, natural numbers, or sets):

Declaring primary types

▶ Run
💡
Type names can use Unicode characters like ℕ, 𝕊, 𝔹. This allows mathematical notation in your code.

Function Types

Functions are typed using the arrow notation [Args -> Result]:

for(f: [A -> B]) // Function from A to Bfor(g: [A, B -> C]) // Function taking A and B, returning Cfor(h: [A, [B -> C] -> D]) // Higher-order function taking A and [B -> C] (function taking B, returning C), returning D

Declarations of functional type atoms

▶ Run

Type Scoping

Types are scoped — they are visible inside the type() scope:

Type scoping

▶ Run

Type Polymorphism

Formall supports type polymorphism in two ways. A type parameter of a theorem: declare type(T) inside the theorem, prove it, and instantiate it with a concrete type by a call (see Calls — Type Parameters). And a type variable: a type whose name starts with an apostrophe, type('α). An atom whose type contains 'α is polymorphic — one atom for all types, its type is inferred at every application (as in HOL and Lean). A statement with 'α in the types of its bound atoms is a schema — true for every type: calls and the search for conditions instantiate 'α by matching.

A polymorphic quantifier and an axiom schema

Atoms in Formall are variables (for means «for any»), so a polymorphic atom does not claim that a type is inhabited: empty types stay sound.

▶ Run

Why Types Matter

Types in Formall serve several purposes:

  • Safety — prevent meaningless expressions like applying a boolean function to a natural number
  • Clarity — make the domain of discourse explicit
  • Verification — enable automatic checking of proof steps
  • Quantification — for and constructors quantify over specific types
ℹ
Unlike some proof assistants, Formall doesn't have a built-in type hierarchy. All types are independent unless you define relationships between them.