Skip to content

Dependent pattern matching syntax in F* #2939

Answered by nikswamy
yiyuan-cao asked this question in Q&A
Discussion options

You must be logged in to vote

Pattern matching in F* is dependent, by default, since F* checks the branches in a context that includes equations between the matched term (aka the scrutinee) and the pattern.

That is, you can write:

type t : Type =
  | TB
  | TI

let bool_or_int = function
  | TB -> bool
  | TI -> int
  
let ex (x:t) : bool_or_int x =
  match x with
  | TB -> true
  | TI -> 0

and F* automatically converts from bool or int to bool_or_int x in each branch. To do this conversion, it generates a proof obligation for Z3 to check that the two types are provably equal, i.e., roughly, in the first branch, the goal to Z3 looks like x:t, x==TB |- bool == bool_or_int x, and similarly for the second branch.

Sometim…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by yiyuan-cao
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants