简体   繁体   English

Haskell标准-'nf'应用于过少的参数

[英]Haskell Criterion - 'nf' is applied to too few arguments

I am a new guy to Haskell. 我是Haskell的新手。 I am working a benchmark(Criteriaon) on binary search algorithm. 我正在对二进制搜索算法进行基准测试(Criteriaon)。 I keep getting error: 'nf' is applied to too few arguments what am I doing wrong. 我不断收到错误消息:'nf'应用于的参数太少了,我在做什么错。

Thanks 谢谢

binSear array serNum lowInx highInx
   | highInx < lowInx       = -1
   | array!!sred > serNum = binSear array serNum lowInx (mid-1)
   | array!!sred < serNum = binSear array serNum (mid+1) highInx
   | otherwise            = mid
   where
   mid = lowInx + ((highInx - lowInx) `div` 2)

main = do
        let arr = [1..10000000]
        defaultMain [
            bench "1" $ nf (binSear arr 54527 0 9999999)
          ]

The type of nf is (a->b)->a->b , so it expects two parameters: a function and an input to that function. nf的类型是(a-> b)-> a-> b ,因此它需要两个参数:一个函数和对该函数的输入。 The function should produce a Benchmarkable. 该函数应产生一个Benchmarkable。

In your case, you are just passing one parameter to nf : the function itself, but that function is fully applied, so it's not expecting any additional parameter, nor are you passing that extra parameter. 在您的情况下,您只是将一个参数传递给nf :函数本身,但是该函数已完全应用,因此它不希望有任何附加参数,也不会传递该附加参数。 In this case, you should partially apply the function and pass that extra parameter to nf. 在这种情况下,您应该部分应用该函数并将该额外参数传递给nf。

You may be forced to reorder the parameters of binSear or create a helper lambda to do so, to ensure that the currying happens in the last parameter, and you should pass that parameter to nf outside of the parenthesis. 您可能被迫重新排序binSear的参数或创建一个辅助lambda来这样做,以确保在最后一个参数中发生弯曲,并且应将该参数传递到括号之外的nf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM