From a22acd57e867422e187c47d27130c968fd1f3276 Mon Sep 17 00:00:00 2001 From: Kim Morrison Date: Mon, 9 Sep 2024 11:10:20 +1000 Subject: [PATCH] =?UTF-8?q?chore:=20turn=20off=20`Inhabited=20(Sum=20?= =?UTF-8?q?=CE=B1=20=CE=B2)`=20instances=20(#5284)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Alternative to #5270. --- src/Init/Core.lean | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/Init/Core.lean b/src/Init/Core.lean index eb7d29acec11..77c64a7ece33 100644 --- a/src/Init/Core.lean +++ b/src/Init/Core.lean @@ -165,9 +165,23 @@ inductive PSum (α : Sort u) (β : Sort v) where @[inherit_doc] infixr:30 " ⊕' " => PSum -instance {α β} [Inhabited α] : Inhabited (PSum α β) := ⟨PSum.inl default⟩ +/-- +`PSum α β` is inhabited if `α` is inhabited. +This is not an instance to avoid non-canonical instances. +-/ +@[reducible] def PSum.inhabitedLeft {α β} [Inhabited α] : Inhabited (PSum α β) := ⟨PSum.inl default⟩ + +/-- +`PSum α β` is inhabited if `β` is inhabited. +This is not an instance to avoid non-canonical instances. +-/ +@[reducible] def PSum.inhabitedRight {α β} [Inhabited β] : Inhabited (PSum α β) := ⟨PSum.inr default⟩ + +instance PSum.nonemptyLeft [h : Nonempty α] : Nonempty (PSum α β) := + Nonempty.elim h (fun a => ⟨PSum.inl a⟩) -instance {α β} [Inhabited β] : Inhabited (PSum α β) := ⟨PSum.inr default⟩ +instance PSum.nonemptyRight [h : Nonempty β] : Nonempty (PSum α β) := + Nonempty.elim h (fun b => ⟨PSum.inr b⟩) /-- `Sigma β`, also denoted `Σ a : α, β a` or `(a : α) × β a`, is the type of dependent pairs @@ -1150,12 +1164,20 @@ end Subtype section variable {α : Type u} {β : Type v} -instance Sum.inhabitedLeft [Inhabited α] : Inhabited (Sum α β) where +/-- This is not an instance to avoid non-canonical instances. -/ +@[reducible] def Sum.inhabitedLeft [Inhabited α] : Inhabited (Sum α β) where default := Sum.inl default -instance Sum.inhabitedRight [Inhabited β] : Inhabited (Sum α β) where +/-- This is not an instance to avoid non-canonical instances. -/ +@[reducible] def Sum.inhabitedRight [Inhabited β] : Inhabited (Sum α β) where default := Sum.inr default +instance Sum.nonemptyLeft [h : Nonempty α] : Nonempty (Sum α β) := + Nonempty.elim h (fun a => ⟨Sum.inl a⟩) + +instance Sum.nonemptyRight [h : Nonempty β] : Nonempty (Sum α β) := + Nonempty.elim h (fun b => ⟨Sum.inr b⟩) + instance {α : Type u} {β : Type v} [DecidableEq α] [DecidableEq β] : DecidableEq (Sum α β) := fun a b => match a, b with | Sum.inl a, Sum.inl b =>