简体   繁体   English

忽略 Isabelle 中缺失的模式

[英]Ignore missing pattern in Isabelle

For example, I would like to define a function that extracts the first element of a list.例如,我想定义一个提取列表第一个元素的 function。 For this function, I do not care about the case when the list is empty (eg I can make sure that every time I use the function, I will pass a non-empty list).对于这个 function,我不关心列表为空的情况(例如我可以确保每次使用 function 时,我都会传递一个非空列表)。 But Isabelle would warn that但伊莎贝尔会警告说

Missing patterns in function definition:
extracts [] = undefined

How can I deal with situations like this?我该如何处理这样的情况?

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"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM