Implements the pretty printer option `pp.numericTypes` for including a type ascription for numeric literals. For example, `(2 : Nat)`, `(-2 : Int)`, and `(-2 / 3 : Rat)`. This is useful for debugging how arithmetic expressions have elaborated or have been otherwise transformed. For example, with exponentiation is is helpful knowing whether it is `x ^ (2 : Nat)` or `x ^ (2 : Real)`. This is like the Lean 3 option `pp.numeralTypes` but it has a wider notion of a numeric literal. Also implements the pretty printer option `pp.natLit` for including the `nat_lit` prefix for raw natural number literals. Closes #3021
99 lines
1.3 KiB
Text
99 lines
1.3 KiB
Text
import Lean.Data.Rat
|
|
|
|
/-!
|
|
Tests for `pp.numericTypes` and `pp.natLit`
|
|
|
|
RFC #3021
|
|
-/
|
|
|
|
open Lean (Rat)
|
|
|
|
section
|
|
|
|
/-!
|
|
Both raw nat lits and non-raw natural numbers pretty print the same by default
|
|
-/
|
|
#check nat_lit 22
|
|
#check 22
|
|
|
|
set_option pp.natLit true
|
|
|
|
/-!
|
|
The raw nat lit pretty prints with the `nat_lit` prefix when `pp.natLit` is true.
|
|
-/
|
|
#check nat_lit 22
|
|
#check 22
|
|
|
|
end
|
|
|
|
section
|
|
set_option pp.numericTypes true
|
|
|
|
/-!
|
|
The `pp.numericTypes` option sets `pp.natLit` to true.
|
|
-/
|
|
#check nat_lit 22
|
|
|
|
/-!
|
|
Natural number literal
|
|
-/
|
|
#check (22 : Rat)
|
|
|
|
/-!
|
|
Negative integer literal
|
|
-/
|
|
#check (-22 : Rat)
|
|
|
|
/-!
|
|
Rational literal of two natural numbers
|
|
-/
|
|
#check (22 / 17 : Rat)
|
|
|
|
/-!
|
|
Rational literal of a negative integer and a rational
|
|
-/
|
|
#check (-22 / 17 : Rat)
|
|
|
|
/-!
|
|
Not a rational literal since the denominator is negative.
|
|
-/
|
|
#check (-22 / -17 : Rat)
|
|
|
|
/-!
|
|
Natural number literal for `Fin`.
|
|
-/
|
|
#check (17 : Fin 22)
|
|
|
|
/-!
|
|
Natural number literal for `Nat`.
|
|
-/
|
|
#check 2
|
|
|
|
/-!
|
|
Natural number literals in the context of an equation.
|
|
-/
|
|
#check 2 + 1 = 3
|
|
|
|
/-!
|
|
Testing `pp.all` override. The `2` should not appear with `nat_lit` in the `OfNat.ofNat` expression.
|
|
-/
|
|
set_option pp.all true
|
|
#check 2
|
|
|
|
end
|
|
|
|
section
|
|
set_option pp.all true
|
|
|
|
/-!
|
|
Testing `pp.all`.
|
|
-/
|
|
#check 2
|
|
|
|
/-!
|
|
Testing `pp.all` when `pp.natLit` is *explicitly* set to true.
|
|
-/
|
|
set_option pp.natLit true
|
|
#check 2
|
|
|
|
end
|