Zulip Chat Archive
Stream: lean4
Topic: Monad variable puzzle
Damiano Testa (Oct 29 2024 at 22:55):
In what is below, noMonad
does not use [Monad m]
.
import Lean.Environment
open Lean
variable {m : Type → Type} [Monad m]
def noMonad [MonadEnv m] : m Environment := do getEnv
/-- info: noMonad {m : Type → Type} [MonadEnv m] : m Environment -/
#guard_msgs in
#check noMonad
What happens if you remove [Monad m]
from variable
?
Edward van de Meent (Oct 29 2024 at 23:03):
ah. i guess that sortof makes sense?
Edward van de Meent (Oct 29 2024 at 23:04):
not really, but sortof?
Damiano Testa (Oct 29 2024 at 23:06):
I probably agree: I am still undecided on whether I think that it is cool or that it should not work.
Edward van de Meent (Oct 29 2024 at 23:13):
i guess MonadEnv
basically is a misnomer compared to what it does?
Edward van de Meent (Oct 29 2024 at 23:13):
and we can either change the way it works, or its name?
Damiano Testa (Oct 29 2024 at 23:14):
I'm not sure that it is MonadEnv
that is at fault there. You can get a similar outcome with other MonadXXX
classes.
Edward van de Meent (Oct 29 2024 at 23:17):
it makes sense that you'd expect MonadXXX
to be somehow related to Monads?
Edward van de Meent (Oct 29 2024 at 23:17):
so either we make them be related, or we change the name?
Damiano Testa (Oct 29 2024 at 23:22):
I am not sure that there is anything to be changed, I just find the rules for inclusion of variables in declaration surprising, that's all.
Edward van de Meent (Oct 29 2024 at 23:25):
i guess there's two surprises here. the first is that, despite the fact that Monad m
doesn't get used here, its existance as an assumption is required in order to allow do
notation. The second is that using a MonadEnv
assumption doesn't somehow require you to have Monad
already (resulting in the error with do
notation when you remove the Monad
assumption, rather than an error at MonadEnv
).
Damiano Testa (Oct 29 2024 at 23:27):
Yes, but I am not too surprised to find out that MonadXXX
does not actually require Monad
.
Edward van de Meent (Oct 29 2024 at 23:29):
but it's in the name?
Edward van de Meent (Oct 29 2024 at 23:30):
it doesn't make sense as a class without?
Damiano Testa (Oct 29 2024 at 23:37):
To me, the name suggests that Monad
will be relevant, which it is. As for making sense... Lean is happy with it, so I'm happy to accept that it does make sense! :upside_down:
Kyle Miller (Oct 30 2024 at 00:10):
I wonder if there are other typeclasses that you need to have present to elaborate but do not appear in the final type.
Damiano Testa (Oct 30 2024 at 00:11):
I do not know: I found out about this since the "unused variable command linter" that I am writing told me that Monad m
was not needed and when I went to remove it, I got slapped!
Damiano Testa (Oct 30 2024 at 00:12):
(The specific MonadXXX
that was being used was MonadMCtx
, though this is probably irrelevant.)
Damiano Testa (Oct 30 2024 at 00:13):
See docs#Mathlib.Tactic.modifyMetavarDecl.
Damiano Testa (Oct 30 2024 at 00:14):
In that case, removing Monad m
and do
is an option! :smile:
Damiano Testa (Oct 30 2024 at 00:23):
I am not sure if there are some unexpected consequences in the removal, but #18420 is a PR making the linter happier.
Kyle Miller (Oct 30 2024 at 00:25):
Looks good, there are no consequences to that
Kyle Miller (Oct 30 2024 at 00:26):
Incidentally I was just noticing that MonadEnv didn't need Monad a few days ago
Damiano Testa (Oct 30 2024 at 00:26):
If I find more surprising removals, I will flag them, but so far all the removals have been pretty boring: a file has been split, variable
s have been copied, but are now unused. Mostly.
Damiano Testa (Oct 30 2024 at 00:28):
Kyle Miller said:
Incidentally I was just noticing that MonadEnv didn't need Monad a few days ago
I view this a little like when in mathlib you define "local rings" and there is nothing "local" about them: in my mind, the fact that MonadXXX
may not require Monad
seems just an implementation detail.
Last updated: May 02 2025 at 03:31 UTC