Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell 模式匹配冗余_Haskell_Pattern Matching - Fatal编程技术网

Haskell 模式匹配冗余

Haskell 模式匹配冗余,haskell,pattern-matching,Haskell,Pattern Matching,我怎样才能确定图案 func (2:xs) = expression func (2:x:xs) = expression2 其中2:xs是长度为2的列表,与模式不匹配 func (2:xs) = expression func (2:x:xs) = expression2 其中2:x:xs是长度为3的列表?用空括号结束列表模式: func (2:x:[]) = expression 这将确保x是列表中的单个元素。根据需要进行调整: func [] = ... -- empty cas

我怎样才能确定图案

func (2:xs) = expression
func (2:x:xs) = expression2
其中2:xs是长度为2的列表,与模式不匹配

func (2:xs) = expression
func (2:x:xs) = expression2

其中2:x:xs是长度为3的列表?

用空括号结束列表模式:

func (2:x:[]) = expression
这将确保
x
是列表中的单个元素。

根据需要进行调整:

func [] = ... -- empty case
func [x] = ... -- length=1 case
func [x,y] = ... -- length=2 case
func (x:y:z:zs) = ... -- length>=3 case

2:xs
是长度至少为1的列表,而不是长度为2的列表。