Zulip Chat Archive

Stream: new members

Topic: Meaning of "prelude" at start of lean 4 file.


Richard L Ford (Jan 18 2022 at 22:31):

I'm reading the lean4 sources. Can someone tell me what is the effect of starting a file with "prelude"? I notice that Prelude.lean starts like that, so I thought it might trigger some kind of special treatment, but I see other files that start with "prelude" as well.

Ruben Van de Velde (Jan 18 2022 at 22:33):

The prelude is the code that's included when you don't import anything explicitly

Anne Baanen (Jan 18 2022 at 22:35):

(In Lean 3 at least) prelude means "don't import any files implicitly"

Arthur Paulino (Jan 18 2022 at 22:37):

I think it's the same in Lean 4:

prelude

#check Nat
-- unknown identifier 'Nat'
-- unknown constant 'sorryAx'

Mario Carneiro (Jan 18 2022 at 22:50):

Every file implicitly starts with import Init (lean 4) or import init (lean 3). Using prelude at the top of the file deletes this implicit import. This is required for any file that is imported by the Init module (i.e. the prelude itself) in order to avoid a circular import, but it is generally not recommended for anything else.

Richard L Ford (Jan 18 2022 at 22:51):

Thanks. That makes sense.


Last updated: Dec 20 2023 at 11:08 UTC