繁体   English   中英

f#中不完整的模式匹配

[英]Incomplete Pattern Matching in f#

请考虑以下代码:

let list1 = [1; 2; 3; 4; 5];;
let getThird3 = function 
  |[] ->[];
  | _::_::l3::t -> t;;
getThird3 list1;

当粘贴在运行fsharpi的终端上时,它会给我这个错误

> let list1 = [1; 2; 3; 4; 5];;

val list1 : int list = [1; 2; 3; 4; 5]

> let getThird3 = function 
-  |[] ->[];
-  | _::_::l3::t -> t;;

let getThird3 = function 
----------------^^^^^^^^

/Users/nickolasmorales/stdin(17,17): warning FS0025: Incomplete pattern matches on this expression. For example, the value '[_;_]' may indicate a     case not covered by the pattern(s).

val getThird3 : _arg1:'a list -> 'a list

有什么建议么? 我尝试使用两者:只有TAB和空格,但它在功能后无法识别任何内容。

这只是一个警告:

如果你做了getThird3 [1;2]你会得到一个matchfailureexception。

警告必须选择特定的地方作为警告的基础,并且该function可能与其他任何地方一样好。

要删除警告,我会将匹配更改为

| _::_::l3::t -> t;;
| _ -> failwith "not a long enough list"

暂无
暂无

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

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