Reputation: 15
For example, I would like to define a function that extracts the first element of a list. For this function, I do not care about the case when the list is empty (e.g. I can make sure that every time I use the function, I will pass a non-empty list). But Isabelle would warn that
Missing patterns in function definition:
extracts [] = undefined
How can I deal with situations like this?
Upvotes: 1
Views: 115
Reputation: 1081
You have quite a few options available, for example:
fun extracts where "extracts xs = hd xs"
definition extracts where [simp]: "extracts = hd"
fun extracts where "extracts xs = (case xs of (x # _) ⇒ x)"
fun extracts where "extracts (x # _) = x" | "extracts [] = undefined"
Upvotes: 2