小编tpa*_*ark的帖子

(x:_)和[x:_]是什么意思?

head' :: [a] -> a
head' [] = error "No head for empty lists!"
head' (x:_) = x

head' :: [a] -> a
head' xs = case xs of [] -> error "No head for empty lists!"
                      (x:_) -> x
Run Code Online (Sandbox Code Playgroud)

我要求一个相当容易的问题,我不明白.在上面的代码中,我看到它需要一个输入列表.但在第三行,它说(x:_)哪些让我感到困惑.任何人都可以向我解释为什么他们写(x:_)而不是[x:_]

而且,我不明白是什么(x:_)意思.

谢谢.

haskell list pattern-matching

5
推荐指数
2
解决办法
6175
查看次数

标签 统计

haskell ×1

list ×1

pattern-matching ×1