Zulip Chat Archive

Stream: general

Topic: Are inductive types the only types that can pattern-match?


nrs (Oct 11 2024 at 05:07):

Am trying to understand a bit more about how Lean works. In a type theory we use for example pi types to define inductive types, so inductive types are not the only possible types in a type theory. In the specific case of Lean, are inductive types the only ones that can be pattern-matched?

Marcus Rossel (Oct 11 2024 at 06:01):

There are only three kinds of types you can construct in Lean: pi types, type universes, and inductive types. Since the first two can't be pattern matched, inductive types are the only ones that can.

nrs (Oct 11 2024 at 06:02):

Marcus Rossel said:

There are only three kinds of types you can construct in Lean: pi types, type universes, and inductive types. Since the first two can't be pattern matched, inductive types are the only ones that can.

I see! I wasn't sure how much of Lean's type system is exhausted by inductive types, thank you very much for the answer!

Etienne Marion (Oct 11 2024 at 06:14):

Marcus Rossel said:

There are only three kinds of types you can construct in Lean: pi types, type universes, and inductive types. Since the first two can't be pattern matched, inductive types are the only ones that can.

Aren’t there quotient types too?

Floris van Doorn (Oct 11 2024 at 12:57):

And I guess you can "define" types using choice. But you can definitely not pattern match on those.

import Mathlib.Tactic

noncomputable def «Don'tDoThis» : Type :=
  Classical.choose (p := fun α : Type  Nat.card α = 3) Fin 3, by simp

Last updated: May 02 2025 at 03:31 UTC