[英]Could not find module ‘Criterion.Main’
I have copied the following code from criterion tutorial: 我从标准教程中复制了以下代码:
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
]
]
I am getting the following error: 我收到以下错误:
fiber.hs:1:1: error: Could not find module 'Criterion.Main' Use -v to see a list of the files searched for. fiber.hs:1:1:错误:找不到模块'Criterion.Main'使用-v查看搜索到的文件的列表。 |
| 1 |
1 | import Criterion.Main |
导入Criterion.Main | ^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^
The GHC version I am using is 8.4.2 and cabal version is 2.2.0.0. 我正在使用的GHC版本是8.4.2,而阴谋集团版本是2.2.0.0。
I tried to install the criterion package by: 我尝试通过以下方式安装标准包:
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
One approach would be to use the Stack script interpreter to run this. 一种方法是使用Stack脚本解释器运行此脚本。 In order to do so, you would first install Stack , then add the script interpreter bits to the top of your file, eg:
为此,您首先要安装Stack ,然后将脚本解释器位添加到文件的顶部,例如:
#!/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
]
]
Note that I added the --optimize
option on the second line to ensure that Stack would compile your code with optimizations on, instead of the default of using runghc
. 请注意,我在第二行添加了
--optimize
选项,以确保Stack将在启用优化的情况下编译代码,而不是使用runghc
的默认runghc
。
And finally run the file with stack fiber.hs
(or whatever you called the file). 最后,使用
stack fiber.hs
(或任何您称为文件)运行文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.