Zulip Chat Archive

Stream: general

Topic: match on option


Scott Morrison (Apr 01 2020 at 01:37):

if I have o : option A, and write

match o with
| some a := ...
| none := ...
end

how can I access the fact o.is_none in the second branch?

Scott Morrison (Apr 01 2020 at 01:37):

Of course I could write an if h : o.is_some then ... else ..., at the cost of slightly less pretty extraction of the some.

Mario Carneiro (Apr 01 2020 at 01:39):

you could match on o, o.is_some, rfl : \forall o b, o.is_some = b -> ... with some a, tt, rfl and none, ff, rfl

Bryan Gin-ge Chen (Apr 01 2020 at 01:54):

(deleted)

Kevin Buzzard (Apr 01 2020 at 07:48):

This match on rfl technique comes up once every couple of months. Examples of this technique should be put in the docs


Last updated: Dec 20 2023 at 11:08 UTC