Zulip Chat Archive

Stream: lean4

Topic: noncomputable/irrelevant fields


Reid Barton (Jan 28 2021 at 16:45):

Has there been consideration of a feature like

structure Foo where
  x : Int
  noncomputable y : Int

meaning

  • Foo.y becomes noncomputable
  • Foo.mk x y is computable as soon as x is
  • A Foo does not store the value y at runtime

It's possible to emulate this with a Erased type, but at the cost of some definitional equalities.

Mario Carneiro (Jan 28 2021 at 16:47):

(I just noticed that erased.out isn't marked noncomputable in the doc gen. We should probably do something about that)

Mario Carneiro (Jan 28 2021 at 16:49):

What is the type of Foo.mk? Is it possible to define a function with the same computability behavior as the proposed Foo.mk constructor?

Mario Carneiro (Jan 28 2021 at 16:51):

It might be easier to actually have an Erased type constructor. It can't really be a type alias because then the VM could confuse A and Erased A if a lean function abuses the defeq

Reid Barton (Jan 28 2021 at 17:00):

Right, I don't know how Lean determines which parts of the program are runtime relevant, but if it's based entirely on type information, then a special structure Erased A where val : A which gets erased would already be helpful

Mario Carneiro (Jan 28 2021 at 17:16):

The key function for this seems to be https://github.com/leanprover/lean4/blob/master/src/library/compiler/util.cpp#L401-L414 . I can't find any function along these lines in lean, although there is Arg.irrelevant and IRType.irrelevant for tracking it


Last updated: Dec 20 2023 at 11:08 UTC