Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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
List 传递两个列表时出现Haskell类型匹配错误_List_Haskell_Type Mismatch - Fatal编程技术网

List 传递两个列表时出现Haskell类型匹配错误

List 传递两个列表时出现Haskell类型匹配错误,list,haskell,type-mismatch,List,Haskell,Type Mismatch,我正在开始学习Haskell,并且必须创建一个非常简单的函数,该函数包含两个列表并将它们合并 app :: [a] -> [a] -> [a] app xs ys = xs ++ ys 这是我们必须对这些较小功能进行基准测试的任务的一部分。 我这样做是有标准的。完整代码如下所示: import Criterion.Main main = defaultMain [ bgroup "normal 100" [ bench "app" $ whnf app $ [0

我正在开始学习Haskell,并且必须创建一个非常简单的函数,该函数包含两个列表并将它们合并

app :: [a] -> [a] -> [a]  
app xs ys = xs ++ ys  
这是我们必须对这些较小功能进行基准测试的任务的一部分。
我这样做是有标准的。完整代码如下所示:

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错误消息时遇到了一个真正的问题,我基本上被困在这里了
我知道这里有很多关于类型不匹配的问题,但我找不到解决方案

提前谢谢

工作台和
whnf
的签名为:

bench :: String        -> Benchmarkable -> Benchmark
whnf  :: (a -> b) -> a -> Benchmarkable
由于
app
接受两个参数,因此我们需要在调用
whnf
时插入第一个参数:

whnf (app [0..49]) [50..100]  :: Benchmarkable
请注意,
whnf
有两个参数:
(app[0..49])
[50..100]

现在我们可以形成对
bench
的调用:

bench "app" ( whnf (app [0..49]) [50..100] )  :: Benchmark
如果我们想使用$,只有一个地方可以使用它:

bench "app" $ whnf (app [0..49]) [50..100]
我们不能在
whnf
之后放置$,因为通常:

a b c   ==  (a b) c


我建议您在任何地方都不要使用
$
来重写它,只使用括号,然后如果您真的想让它工作的话,再添加
$
。@AlexisKing是的,我已经尝试过了,但是我遇到了同样的错误,所以我把它们留在了里面。这是有道理的。谢谢!
a $ b c == a (b c)