haskell - 使用标准的类型错误

标签 haskell haskell-criterion

我阅读了文档和一些讨论该包的文章,但我是 Haskell 的新手,不太了解,但我尝试过......

以下是我所做的:

module Main where  
{-# LANGUAGE BangPatterns #-}   
import Control.Parallel(par,pseq)  
import Control.Exception  
import Data.List  
import IO  
import Data.Char  
import Criterion.Main (defaultMain, bench)  

learquivo :: FilePath -> IO ([[Int]])  
learquivo "mkList1.txt"  = do   
    conteudo <- readFile "mkList1.txt" 
    return (read conteudo) 


main = defaultMain [  
    bench "map sort learquivo" $ \n -> map sort learquivo
    ]

当它执行时,发生以下错误:

Couldn't match expected type [[a]]
       against inferred type FilePath -> IO [[Int]]

最佳答案

为了让您了解我通常如何使用 nfwhnf 函数运行它,我将给出我的代码:

import Data.List
import Criterion.Main

main :: IO ()
main = do
   -- content <- learquivo "mkList1.txt"  
   let content = [ [big, big - step.. 0] | big <- [1000..1010], step <- [1..5]] :: [[Int]]
   defaultMain
        [ bench "benchmark-name" (nf (map sort) content)]

编辑:如果你喜欢这个,那么也尝试一下绘图:

module Main where

import Data.List
import Criterion.Main
import Criterion.Config
import Criterion.MultiMap as M

main :: IO ()
main = do
   let myConfig = defaultConfig {
              -- Always display an 800x600 window with curves.
              cfgPlot = M.singleton KernelDensity (Window 800 600)
              }
   let content = [ [big, big-step.. 0] | big <- [1000..1010], step <- [1..5]] :: [[Int]]
   defaultMainWith myConfig (return ())
        [ bench "benchmark-name" (nf (map sort) content)]

关于haskell - 使用标准的类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4033103/

相关文章:

Haskell "dependent"记录字段?

haskell - 如何将条件与堆栈一起使用

通过多行模式匹配的函数声明

haskell - 如何使用 Lenses 遍历并分配给 Map 中的某些(但不是全部)元素

haskell - 使用 Criterion 对 IO 操作进行基准测试

haskell - 为什么仅对功能设计进行微小更改就会从根本上改变标准基准测试的结果?

haskell - 根据标准生成 HTML 输出

haskell - 初始化标准中的基准并从结果中排除初始化时间

haskell - 计算列表的众数

string - 在 Haskell 中比较两个字符串