Zulip Chat Archive

Stream: lean4

Topic: unreachable match case


Arthur Paulino (Apr 12 2022 at 13:09):

Is it possible to replace the unreachable! with some proof that any other possibility except for bool _ is unreachable because the return of Literal.eq is always a Literal.bool?

inductive Literal
  | bool  : Bool    Literal
  | int   : Int     Literal
  | float : Float   Literal
  | str   : String  Literal

def Literal.eq : Literal  Literal  Literal
  | bool  bₗ, bool  b => bool $ bₗ == b
  | int   iₗ, int   i => bool $ iₗ == i
  | float fₗ, float f => bool $ fₗ == f
  | int   iₗ, float f => bool $ (.ofInt iₗ) == f
  | float fₗ, int   i => bool $ fₗ == (.ofInt i)
  | str   sₗ, str   s => bool $ sₗ == s
  | _       , _        => bool false

def Literal.isEq (l r : Literal) : Bool :=
  match h : l.eq r with
  | .bool b => b
  | x       => unreachable!

Sebastian Ullrich (Apr 12 2022 at 13:17):

There may be various workarounds, but have you considered making Literal (and, presumably, other similar types) "intrinsically typed" by parameterizing/indexing it with the type of the value it carries? Then Literal.eq could have type Literal t -> Literal t -> Literal .bool.

Sebastian Ullrich (Apr 12 2022 at 13:17):

Whether that is a good idea in the greater context depends on a few other things, e.g. on how complex your type system is.

Arthur Paulino (Apr 12 2022 at 13:18):

In my case I need all Literals to be of the same type so I can have, for instance, List Literal with heterogeneous inner types


Last updated: Dec 20 2023 at 11:08 UTC