Zulip Chat Archive

Stream: lean4

Topic: Option Flatten?


Mac (May 17 2021 at 19:05):

Is there code in stdlib for some kind of Option.flatten that compresses an Option stack? For example:

def flatten : Option (Option a) -> Option a
| some v => v
| none => none

This comes up a lot in nested optionals within macros.

Johan Commelin (May 17 2021 at 19:08):

Does Lean 4 know that Option is a monad? Because this is the join.

Mac (May 17 2021 at 19:12):

No, in fact, Option is specifically not a Monad (OptionM is the monad version).


Last updated: Dec 20 2023 at 11:08 UTC