Zulip Chat Archive

Stream: new members

Topic: Difference between def and let


Lambert A'Campo (Nov 12 2019 at 15:28):

What is the difference between let and def? For example I wanted in the whole file to have

def B : set V := closed_ball 0 1

but then in a later proof I use

intros x hx,

while showing that B is contained in something but it doesn't work. However, if I use let it does work.

Mario Carneiro (Nov 12 2019 at 15:42):

Let and def are morally similar but live in different syntactic classes. As for your particular example we need more context, preferably a MWE

Lambert A'Campo (Nov 12 2019 at 16:11):

What is a MWE?

Johan Commelin (Nov 12 2019 at 16:11):

minimal working example

Lambert A'Campo (Nov 12 2019 at 16:28):

Ok so here is a not quite minimal example and I don't understand why the declaration of the example has type problems.

variables
{V : Type*} [normed_group V] [complete_space V] [normed_space  V]

def B' : set V := closed_ball 0 1

example : B'   (a : V) (H : a  B'), ball a 0.5 :=
begin
  sorry
end

Chris Hughes (Nov 12 2019 at 16:38):

MWE with imports

import analysis.normed_space.basic
open metric
variables
{V : Type*} [normed_group V] [complete_space V] [normed_space  V]

def B' : set V := closed_ball 0 1

example : B'   (a : V) (H : a  B'), ball a 0.5 :=
begin
  sorry
end

The problem is that V is an implicit argument to B' and Lean cannot infer this argument

Chris Hughes (Nov 12 2019 at 16:39):

Writing a ∈ (B' : set V) fixes the problem.

Lambert A'Campo (Nov 12 2019 at 16:40):

Oh ok thank you!

Reid Barton (Nov 12 2019 at 16:43):

In particular, variables are not "fixed" throughout a section.


Last updated: Dec 20 2023 at 11:08 UTC