Zulip Chat Archive
Stream: lean4
Topic: Lean 4 monads
Arthur Paulino (Mar 19 2022 at 00:49):
Page 5 of https://leanprover-community.github.io/lt2021/slides/leo-LT2021-meta.pdf has the following diagram:
image.png
I have some questions about it:
- What do those arrows really mean? I don't see a direct relationship between
CommandElabM
andTermElabM
and still it's possible to perform computations in the later from the former throughliftTermElabM
- Are there more "transitions" available like the one mentioned in the previous question?
Mario Carneiro (Mar 19 2022 at 00:56):
The arrows represent "lifts"; this means that you can use a value in a lower monad in a higher monad with no notation (or with liftM
if you want to be explicit or coercion doesn't work)
Mario Carneiro (Mar 19 2022 at 00:57):
If we draw arrows whenever one monad can run another a la liftTermElabM
, then there are generally arrows going in the reverse direction of all present
Arthur Paulino (Mar 19 2022 at 00:59):
What do you mean by "lower" monad in the diagram? Literally the vertical orientation of the image?
(thus TacticM
is lower than TermElabM
?)
Mario Carneiro (Mar 19 2022 at 01:00):
sorry, I mean upward in the diagram
Mario Carneiro (Mar 19 2022 at 01:00):
lower in the dependency hierarchy, more or less
Arthur Paulino (Mar 19 2022 at 01:01):
How is it possible to lift from CommandElabM
to TermElabM
if there's no path between them in the diagram (not even if we invert all arrows)?
Mario Carneiro (Mar 19 2022 at 01:01):
each arrow is a monad stack on top of the lower one, using StateT
and ReaderT
to add some read-write and read-only state respectively (conventionally called State
and Context
in the relevant namespace)
Mario Carneiro (Mar 19 2022 at 01:02):
Inverting an arrow is saying that for example you can run a MetaM
from an IO
context; however you have to provide the Meta.Context
and Meta.State
types to kick it off
Mario Carneiro (Mar 19 2022 at 01:03):
most of the arrows that cross the figure like liftTermElabM
do this by conjuring up some dummy state to operate on
Mario Carneiro (Mar 19 2022 at 01:04):
for example if you are in a CommandElabM
and want to run a TacticM
you need to invent some trivial goal to work on, because the tactic wants a tactic state
Mario Carneiro (Mar 19 2022 at 01:04):
MetaM
wants to know what declaration it is in
Mario Carneiro (Mar 19 2022 at 01:14):
The reverse arrows that I could find are:
Lean.Elab.Tactic.run : TacticM -> TermElabM
runTermElabM, liftTermElabM : TermElabM -> CommandElabM
liftCoreM : CoreM -> CommandElabM
MetaM.run : MetaM -> CoreM
MetaM.toIO : MetaM -> IO
CoreM.toIO : CoreM -> IO
CoreM.run : CoreM -> EIO
runCommandElabM : CommandElabM -> FrontendM
Arthur Paulino (Mar 19 2022 at 01:26):
Thank you!!
Eric Wieser (Jul 20 2023 at 14:24):
docs#MetaM.toIO doesn't seem to exist; has it been renamed?
Notification Bot (Jul 20 2023 at 22:39):
11 messages were moved from this topic to #lean4 > doc-gen4 search slowness by Eric Wieser.
Scott Morrison (Jul 20 2023 at 23:26):
MetaM.toIO is in Lean.Meta.Basic
.
There is also TermElabM.toIO
.
Eric Wieser (Jul 21 2023 at 02:09):
I solved my issue by copying runLinter.lean :)
Mario Carneiro (Jul 21 2023 at 17:45):
By the way, there are two runLinter.lean
s, one in Std and one in Mathlib, basically carbon copies. Should mathlib use std's?
Last updated: Dec 20 2023 at 11:08 UTC