Agda


General

Imports needed

Mutually recursive types

Example from here:

mutual
  data ty-ctx : Set where
    ε    : ty-ctx
    _,-_ : (Δ : ty-ctx)  defn Δ  ty-ctx

  data defn : ty-ctx  Set where
    synonym :  {Δ}  ty Δ  defn Δ
    newtype :  {Δ}  ty Δ  defn Δ

  data ty : ty-ctx  Set where
    wk    :  {Δ τ}  ty Δ  ty (Δ ,- τ)
    defd  :  {Δ τ}  ty (Δ ,- τ)
    bit   :  {Δ}    ty Δ
    __  :  {Δ}    ty Δ  ty Δ  ty Δ

Record type

https://agda.readthedocs.io/en/latest/language/record-types.html

record RecName : Set where
  field
    a :
    b : 𝔹

'Open' a record to bring their field names into default scope.

open RecName

Example from docs:

record Pair (A B : Set) : Set where
  field
    fst : A
    snd : B

geta : Pair A B

Levels

Example from docs:

data _×_ {n m : Level} (A : Set n) (B : Set m) : Set (n ⊔ m) where
   _,_ : A  B  A × B

Example import:

Standard library

Standard library need to be installed separately.

Pragmas

Special comments.

Example:

{-# BUILTIN NATURAL ℕ #-}

agda

associates numbers with elements of the type. So 2 would implicitly mean suc (suc zero).

See: https://plfa.github.io/Naturals/#a-pragma

Space matters: a : Set vs a: Set

The space matters. Looks if we do a: Set, a: will be considered a name.

For example, this works:

data Type : Set where
  Nat : Type

But this doesn't:

data Type: Set where
  Nat : Type
{-
Missing type signature for data definition Type:
when scope checking the declaration
  data Type: Set where
    Nat : Type
 -}

Coq vs agda

False type:

Following comparison is probably a bit too approximative…

Coq Agda
False 𝟘 / ()
unit 𝟙 Unit type
I tt

Precedence

Lower precedence value => higher precedence

Emacs

https://agda.readthedocs.io/en/latest/tools/emacs-mode.html#keybindings

Todo

Unicode

Misc