this is the simplest of the constructions to be ported from C++ to Lean, so I’ll PR this one first. This begins to put each construction into its own file, as it was the case with C++. For validation I developed this in a separate repository at https://github.com/nomeata/lean-constructions/tree/fad715e and checked that all `.recOn` declarations found in Lean and Mathlib are identical (per `==`) to the ones produced by the C code.
46 lines
1,006 B
Text
46 lines
1,006 B
Text
set_option pp.mvars false
|
|
|
|
structure Foo := (n : Nat)
|
|
|
|
def Foo.sum (xs : List Foo) : Foo :=
|
|
xs.foldl (λ s x => ⟨s.n + x.n⟩) ⟨0⟩
|
|
|
|
/--
|
|
info: let x1 := { n := 1 };
|
|
let x2 := { n := 2 };
|
|
let x3 := { n := 3 };
|
|
let x5 := { n := 5 };
|
|
let x6 := { n := 6 };
|
|
Foo.sum [x1, x2, x3, x5, x6] : Foo
|
|
-/
|
|
#guard_msgs in
|
|
#check
|
|
let x1 := ⟨1⟩
|
|
let x2 := ⟨2⟩
|
|
let x3 := ⟨3⟩
|
|
-- let x4 := ⟨4⟩; -- If this line is uncommented we get the error at `⟨`
|
|
let x5 := ⟨5⟩
|
|
let x6 := ⟨6⟩
|
|
Foo.sum [x1, x2, x3, x5, x6]
|
|
|
|
/--
|
|
error: invalid constructor ⟨...⟩, expected type must be an inductive type ⏎
|
|
?_
|
|
---
|
|
info: let x1 := { n := 1 };
|
|
let x2 := { n := 2 };
|
|
let x3 := { n := 3 };
|
|
let x4 := ?_ x1 x2 x3;
|
|
let x5 := { n := 5 };
|
|
let x6 := { n := 6 };
|
|
Foo.sum [x1, x2, x3, x5, x6] : Foo
|
|
-/
|
|
#guard_msgs in
|
|
#check
|
|
let x1 := ⟨1⟩
|
|
let x2 := ⟨2⟩
|
|
let x3 := ⟨3⟩
|
|
let x4 := ⟨4⟩; -- If this line is uncommented we get the error at `⟨`
|
|
let x5 := ⟨5⟩
|
|
let x6 := ⟨6⟩
|
|
Foo.sum [x1, x2, x3, x5, x6]
|