Zulip Chat Archive
Stream: new members
Topic: Nontermating "do" blocks
Ayden Coughlin (Oct 22 2023 at 23:31):
When reading about the "do" notation in the Lean manual, I started experimenting and noticed that you're able to write nonterminating functions without Lean complaining:
def loops : IO Unit := do
while true do
pure ()
Why are you not required to mark this function as "partial"?
Mario Carneiro (Oct 23 2023 at 01:57):
"partial" is not a viral marker, it is only used for definitions that are directly recursive, and implies that they cannot be unfolded
Mario Carneiro (Oct 23 2023 at 01:58):
There is a partial
involved in defining while
, but your code is only calling that definition so you have no direct recursion in your function (i.e. loops
does not call itself)
Mario Carneiro (Oct 23 2023 at 01:58):
(the partial
is in src#Lean.Loop.forIn)
Ayden Coughlin (Oct 23 2023 at 12:38):
I see. Thank you.
Ayden Coughlin (Oct 27 2023 at 03:10):
This concerns me a little bit. How can I be confident that my function terminates if it can depend on partial functions indirectly in this way? Also, are there alternatives to while
and similar imperative-style constructs that are not partial (requiring some kind of manual proof of termination)?
Mario Carneiro (Oct 27 2023 at 03:44):
If you use tail-recursion, then you will have to prove termination manually, or use partial
Last updated: Dec 20 2023 at 11:08 UTC