Zulip Chat Archive

Stream: lean4

Topic: DecidableEq on Ordering


Yakov Pechersky (Apr 29 2021 at 22:02):

What's the right way to provide the instance here? I couldn't find it in the current core

import Lean

open Ordering

instance : DecidableEq Ordering
| lt, lt => isTrue rfl
| eq, eq => isTrue rfl
| gt, gt => isTrue rfl
| x, y => isFalse (λ h => Ordering.noConfusion h) -- Sort error here

-- Lean 3 style, also doesn't work
-- instance : DecidableEq Ordering := λ a b =>
--   match a, b with
--     | lt, lt => isTrue rfl
--     | eq, eq => isTrue rfl
--     | gt, gt => isTrue rfl
--     | x, y => isFalse (λ h => Ordering.noConfusion h)

Mario Carneiro (Apr 29 2021 at 22:09):

here's one option

instance : DecidableEq Ordering := by
  intro x y
  cases x <;> cases y <;> first
  | exact isTrue rfl
  | exact isFalse (λ h => Ordering.noConfusion h)

Yakov Pechersky (Apr 29 2021 at 22:14):

Why does this work but the term mode doesn't?

Mario Carneiro (Apr 29 2021 at 22:15):

Using match, the final case is only elaborated once and has to work for general x, y


Last updated: Dec 20 2023 at 11:08 UTC