Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a more elegant way to write the following Coq code?

Tags:

rocq-prover

match x with
| Some x => Some (Ref x)
| None => None
end.

I have to do this quite a lot, nested matches make code look bad. Is there some more elegant, one liner sort of way to lift things out of Option?

like image 419
abhishek Avatar asked Nov 21 '25 09:11

abhishek


1 Answers

There is option_map function in Coq.Init.Datatypes defined as follows:

Definition option_map (A B:Type) (f:A->B) (o : option A) : option B :=
  match o with
    | Some a => @Some B (f a)
    | None => @None B
  end.

You can use it just like @ejgallego showed in the comments: option_map Ref x.

Here is how you can discover this function:

Search (option _ -> option _).
like image 62
Anton Trunov Avatar answered Nov 25 '25 00:11

Anton Trunov