mathlib documentation

tactic.​derive_inhabited

tactic.​derive_inhabited

Derive handler for inhabited instances

This file introduces a derive handler to automatically generate inhabited instances for structures and inductives. We also add various inhabited instances for types in the core library.

Tries to derive an inhabited instance for inductives and structures.

For example:

@[derive inhabited]
structure foo :=
(a :  := 42)
(b : list )

Here, @[derive inhabited] adds the instance foo.inhabited, which is defined as ⟨⟨42, default (list ℕ)⟩⟩. For inductives, the default value is the first constructor.

If the structure/inductive has a type parameter α, then the generated instance will have an argument inhabited α, even if it is not used. (This is due to the implementation using instance_derive_handler.)

@[instance]
def bin_tree.​inhabited {α : Type u_1} :

Equations
@[instance]

Equations
@[instance]
def rbnode.​inhabited {α : Type u_1} :

Equations
@[instance]
def rbtree.​inhabited {α : Type u_1} {lt : α → α → Prop . "default_lt"} :

Equations
@[instance]
def rbmap.​inhabited {α : Type u_1} {β : Type u_2} {lt : α → α → Prop . "default_lt"} :
inhabited (rbmap α β lt)

Equations