【发布时间】:2011-09-17 20:22:54
【问题描述】:
我是 haskell 初学者。我尝试编写将返回倒数第二个列表元素的函数。
我是这样开始的:
lastButOne :: [a] -> a
lastButOne list = if null list
then
0
else
length list
0 字符串我得到错误:
Couldn't match type `a' with `Int'
`a' is a rigid type variable bound by
the type signature for lastButOne :: [a] -> a
我明白了。但我能在这里做什么?我不知道列表类型。我可以在这里放什么?
谢谢。
【问题讨论】:
-
不清楚您真正想要返回什么。也许有意义吗?
-
@Craig "倒数第二个元素"
-
使类型签名返回一个整数而不是列表类型的“a”