Skip to content
LeanLearn
Level 3~35 minLean 4

Lists, maps and folds

A list is an inductive type: empty, or an element in front of a list. Process lists with recursion and with map, filter and fold, then prove facts about every list by list induction.

You will be able to
  • Write recursive functions on lists with one equation for [] and one for x :: xs.
  • Use the higher-order functions map, filter and foldr.
  • Prove properties of list functions by induction on the list.

Recommended first: Your own data types, Mathematical induction: proving infinitely many cases. You can start anyway. Nothing is locked.

EncounterActivity 1 of 8

Encounter

A shopping list, a playlist, the digits of a number: lists are everywhere. In Lean a list is defined like the trees of the previous lesson, with two constructors:

  • [], the empty list;
  • x :: xs, an element x in front of a smaller list xs.

So [3, 1, 4] is really 3 :: 1 :: 4 :: []. A function on lists has one equation for each constructor, and a proof about every list goes by induction on the list.