无法找到模块'Criterion.Main'

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无法找到模块'Criterion.Main'相关的知识,希望对你有一定的参考价值。

我从标准教程中复制了以下代码:

import Criterion.Main

-- The function we're benchmarking.
fib m | m < 0     = error "negative!"
      | otherwise = go m
  where
    go 0 = 0
    go 1 = 1
    go n = go (n-1) + go (n-2)

-- Our benchmark harness.
main = defaultMain [
  bgroup "fib" [ bench "1"  $ whnf fib 1
               , bench "5"  $ whnf fib 5
               , bench "9"  $ whnf fib 9
               , bench "11" $ whnf fib 11
                ]
     ]

我收到以下错误:

fiber.hs:1:1:错误:找不到模块'Criterion.Main'使用-v查看搜索到的文件列表。 | 1 | import Criterion.Main | ^^^^^^^^^^^^^^^^^^^^^

我使用的GHC版本是8.4.2,cabal版本是2.2.0.0。

我尝试通过以下方式安装标准包:

cabal update
Downloading the latest package list from hackage.haskell.org
To revert to previous state run: cabal update --index-state='2018-06- 
01T04:23:08Z'

cabal install -j --disable-tests criterion
clang: warning: argument unused during compilation: '-nopie' [-Wunused- 
command-line-argument]
.
.
.
.
cabal: Error: some packages failed to install:
abstract-deque-0.3-IvBVpgU2tvq3eILHsBTjFR failed during the building 
phase.
The exception was:
ExitFailure 1
aeson-1.3.1.1-J9Jy9Bz77dxJho59OWZvUt depends on aeson-1.3.1.1 which 
failed to install.
attoparsec-0.13.2.2-5fvnJr9WRPCJj7fMCLKoI7 depends on attoparsec- 
0.13.2.2
which failed to install.
cassava-0.5.1.0-CNxiRQP2h44BSkY7PLw3nv depends on cassava-0.5.1.0 which 
failed
to install.
criterion-1.4.1.0-1CDqJgx5SYk1Xphp8S6hvK depends on criterion-1.4.1.0 
which failed to install.
microstache-1.0.1.1-DUzquwnO02sC17piNr03EI depends on microstache- 
1.0.1.1 which failed to install.
monad-par-0.3.4.8-5Qx7yEAZEkjJbqZykcUjIa depends on monad-par-0.3.4.8 
which failed to install.
monad-par-extras-0.3.3-755mClpwIBoBMORFcN7gCY failed during the 
building phase. The exception was:
ExitFailure 1
scientific-0.3.6.2-65wDZeAE9ZIBkaesoEq4I0 failed during the building 
phase.
The exception was:
ExitFailure 1
statistics-0.14.0.2-GHJ1OiovyXP1FEjV1emzr8 depends on statistics- 
0.14.0.2 which failed to install.
text-short-0.1.2-JRY9FeZhxkoAZrj3rm5IJZ failed during the building 
phase. The exception was:
ExitFailure 1
uuid-types-1.0.3-tE9Bfk2PgXDUPgbtamBdI failed during the building 
phase. The exception was:
ExitFailure 1
答案

一种方法是使用Stack脚本解释器来运行它。为了做到这一点,你将首先install Stack,然后将script interpreter bits添加到您的文件的顶部,例如:

#!/usr/bin/env stack
-- stack --resolver lts-11.10 script --optimize
import Criterion.Main

-- The function we're benchmarking.
fib m | m < 0     = error "negative!"
    | otherwise = go m
where
    go 0 = 0
    go 1 = 1
    go n = go (n-1) + go (n-2)

-- Our benchmark harness.
main = defaultMain [
bgroup "fib" [ bench "1"  $ whnf fib 1
            , bench "5"  $ whnf fib 5
            , bench "9"  $ whnf fib 9
            , bench "11" $ whnf fib 11
                ]
    ]

请注意,我在第二行添加了--optimize选项,以确保Stack会在优化时编译代码,而不是使用runghc的默认值。

最后使用stack fiber.hs(或任何你称之为文件)运行该文件。

以上是关于无法找到模块'Criterion.Main'的主要内容,如果未能解决你的问题,请参考以下文章

text “无法找到模块'react / package.json'”

sh npm无法找到模块'internal / fs'#npm #error

未找到模块。错误,无法解析'@typessvgo'。无法解析"@typessvgo

无法连接到ijavascript内核/无法找到模块'../build/Release/zmq.node'

sh 修复了Karma无法找到模块'../build/safe-execute'错误

ionic-app-script在构建时失败 - 无法找到模块'@ angular / compiler-cli / ngtools2'