我开始学习Haskell,并且必须创建一个非常简单的函数,它需要两个列表并将它们连接起来。通过两个列表时,Haskell类型匹配错误
app :: [a] -> [a] -> [a]
app xs ys = xs ++ ys
这是一个任务的一部分,我们必须对这些小函数进行基准测试。
我用Criterion来做这件事。完整的代码如下:
import Criterion.Main
main = defaultMain [
bgroup "normal 100" [ bench "app" $ whnf app $ [0..49] [50..100]
]
]
app :: [a] -> [a] -> [a]
app xs ys = xs ++ ys
的编译失败,给我留下了这一点:
Couldn't match expected type `[Integer] -> [a0]'
with actual type `[Integer]'
The function `[0 .. 49]' is applied to one argument,
but its type `[Integer]' has none
In the second argument of `($)', namely `[0 .. 49] [50 .. 100]'
In the second argument of `($)', namely
`whnf app $ [0 .. 49] [50 .. 100]'
我在解密GHC错误消息的实际问题,在这里我基本上停留。
我知道这里有很多关于类型不匹配的问题,但我找不到解决方案。
在此先感谢!
我会推荐在不使用'$'的情况下重写这个文件,只使用圆括号,然后在你真正想要的时候加入'$'。 –
@AlexisKing是的,我已经试过,但我得到了同样的错误,所以我把他们留在。 – DShade