Search code examples
functional-programmingisabelletheorem-proving

Ignore missing pattern in Isabelle


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?


Solution

  • You have quite a few options available, for example:

    1. fun extracts where "extracts xs = hd xs"
    2. definition extracts where [simp]: "extracts = hd"
    3. fun extracts where "extracts xs = (case xs of (x # _) ⇒ x)"
    4. fun extracts where "extracts (x # _) = x" | "extracts [] = undefined"