The Pie à-let-mode Reference
#lang pie-a-let-mode | package: pie-a-let-mode |
1 Installing Pie à-let-mode
In DrRacket, open the Package Manager menu (under the File dropdown or similar) and in the Package Source textbox, enter pie-a-let-mode and click the Install button.
If you prefer to use the terminal and have already set up Racket tools on your PATH, simply type raco pkg install pie-a-let-mode.
2 Using Pie à-let-mode in DrRacket
Pie à-let-mode is implemented as a Racket language. While other editors may work, Pie à-let-mode is currently supported best in DrRacket.
et-mode package (pie-a-let-mode) from the Racket package database, open DrRacket. Change the first line to read #lang pie-a-let-mode, and then start typing.
2.1 Type Checker Feedback
If DrRacket’s "Background Expansion" feature is enabled, the type checker will run every time the file is modified, whether or not it is run. Otherwise, invoke the type checker using the "Run" button.
Mousing over well-typed terms will display a tooltip describing the term and its type.
It may be convenient to enable the option in DrRacket to show gold highlighting on errors, because it causes type errors to be highlighted while typing.
Alternatively, it is also possible to use any editor to create a Pie program, and then save it to a file. Run the file with the command-line version of Racket to test it.
The Todo List for DrRacket is supported by Pie. Each TODO in the program is listed.
3 General-Purpose Expressions
type annotation
(the type expr)
> nil Can't determine a type
> (the (List Nat) nil)
(the (List Nat)
nil)
> (cons 2 (same 2)) Can't determine a type
> (the (Σ ((n Nat)) (= Nat n n)) (cons 2 (same 2)))
(the (Σ ((n Nat))
(= Nat n n))
(cons 2
(same 2)))
> (the (Σ ((n Nat)) (= Nat n 2)) (cons 2 (same 2)))
(the (Σ ((n Nat))
(= Nat n 2))
(cons 2
(same 2)))
incomplete expression
4 Types, Constructors, and Eliminators
4.1 Absurd
type constructor
eliminator
(ind-Absurd target motive) → motive
target : Absurd motive : U
4.2 Trivial
type constructor
4.3 Atoms
type constructor
> 'grønkål (the Atom 'grønkål)
> 'agurk (the Atom 'agurk)
4.4 Natural Numbers
type constructor
eliminator
(ind-Nat target motive base step) → (motive target)
target : Nat motive : (-> Nat U) base : (motive zero)
step :
(Π ((n Nat)) (-> (motive n) (motive (add1 n))))
4.5 Pairs
type constructor
(Σ ((x A1) (y A2) ...) D)
type constructor
(Sigma ((x A1) (y A2) ...) D)
type constructor
(Pair A D)
4.6 Functions
type constructor
(Π ((x X1) (y X2) ...) B)
type constructor
(Pi ((x X1) (y X2) ...) B)
type constructor
(∏ ((x X1) (y X2) ...) B)
type constructor
(→ X1 X2 ... B)
type constructor
(-> X1 X2 ... B)
constructor
(λ (x1 x2 ...) b)
> (the (→ Atom Atom Atom) (λ (food beverage) food))
(the (→ Atom Atom
Atom)
(λ (food beverage)
food))
> (the (→ Atom (→ Atom Atom)) (λ (food) (λ (beverage) food)))
(the (→ Atom Atom
Atom)
(λ (food beverage)
food))
> (check-same (→ Atom Atom Atom) (λ (food) (λ (beverage) beverage)) (λ (food beverage) beverage))
constructor
(lambda (x1 x2 ...) b)
4.7 Lists
type constructor
(List E)
eliminator
(ind-List target motive base step) → (motive target)
target : (List E) motive : (-> (List E) U) base : (motive nil)
step :
(Π ((e E) (es (List E))) (-> (motive es) (motive (:: e es))))
> (ind-List (:: 'ananas (:: 'granatæble nil)) (λ (es) Nat) zero (λ (e es len) (add1 len))) (the Nat 2)
> (ind-List (:: 'ananas (:: 'granatæble nil)) (λ (es) (= (List Atom) es es)) (same nil) (λ (e es es=es) (cong es=es (the (→ (List Atom) (List Atom)) (λ (xs) (:: e xs))))))
(the (= (List Atom)
(:: 'ananas
(:: 'granatæble nil))
(:: 'ananas
(:: 'granatæble nil)))
(same (:: 'ananas
(:: 'granatæble nil))))
4.8 Vectors
type constructor
(Vec E len)
eliminator
(ind-Vec target-1 target-2 motive base step)
→ (motive target-1 target-2) target-1 : Nat target-2 : (Vec E target-1)
motive :
(Π ((k Nat)) (→ (Vec E k) U)) base : (motive zero vecnil)
step :
(Π ((k Nat) (e E) (es (Vec E k))) (→ (motive k es) (motive (add1 k) (vec:: e es))))
4.9 Either
type constructor
(Either L R)
eliminator
(ind-Either target motive on-left on-right) → (motive target)
target : (Either X Y) motive : (→ (Either X Y) U)
on-left :
(Π ((l L)) (motive (left l)))
on-right :
(Π ((r R)) (motive (right r)))
4.10 Equality
type constructor
(= X from to)
eliminator
(replace target motive base) → (motive to)
target : (= X from to) motive : (→ X U) base : (motive from)
(→ X Y)
(= Y (fun from) (fun to))
eliminator
target : (= A from to)
motive :
(Π ((x A)) (-> (= A from x) U)) base : (motive from (same from))
4.11 Universe
type constructor
5 Declarations
In addition to expressions, Pie has three syntactic forms that are only valid at the top level of a program.
5.1 Definitions
declaration
(claim x type)
declaration
(define x expr)
5.2 Testing Pie programs
declaration
(check-same type expr1 expr2)
> (check-same Nat 4 4) > (check-same Atom 'kirsebær 'kirsebær) > (check-same Atom 4 'four) Expected Atom but given Nat
> (check-same Atom 'kirsebær 'hindbær) The expressions
'kirsebær
and
'hindbær
are not the same Atom
Because of the η-rules for Π and Absurd, every proof of a negation is the same as every other proof. This is useful when testing programs that produce proofs.
> (check-same (→ (→ (= Nat 2 3) Absurd) (→ (= Nat 2 3) Absurd) (→ (= Nat 2 3) Absurd)) (λ (f g) f) (λ (f g) g))
6 Pie à-let-mode Specific Expressions
local bindings
(let ([id id-expr] ...) expr)
> (check-same (Pair Atom Atom) (let ([x 'one] [y 'two] [p (the (Pair Atom Atom) (cons x y))]) p) (the (Pair Atom Atom) (cons 'one 'two)))
> (check-same (= Nat 2 (add1 (add1 0))) (equal Nat 2 #:by (same 2) (add1 (add1 0))) (same 2))
> (check-same (= Nat 2 (add1 (add1 0))) (equal Nat 2 #:by (same (add1 1)) (add1 1) #:by (same (add1 (add1 0))) (add1 (add1 0))) (trans (the (= Nat 2 (add1 (add1 0))) (same (add1 1))) (the (= Nat 2 (add1 (add1 0))) (same 2))))