使用标准的类型错误
我阅读了文档和一些讨论该包的文章,但我是 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]]
I read the documentation and some articles that talk about the package, but I'm new to Haskell and did not understand much but I tried ....
Below is what I did:
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
]
As it did the following error occurred:
Couldn't match expected type [[a]]
against inferred type FilePath -> IO [[Int]]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了让您了解我通常如何运行它,使用
nf
或whnf
函数,我将给出我的代码:编辑:如果您喜欢这个,那么也尝试一下绘图:
Just so you have how I usually run it, using the
nf
orwhnf
functions, I'll give my code:EDIT: If you like this then also give plotting a try:
问题是这样的:
map sort learquivo
sort
需要一个列表,因此map sort
需要一个列表列表([[a ]]
),而learquivo
的类型是FilePath ->; IO [[Int]]
。您可能想要这样的东西:
您的代码中有很多可以清理的东西,但这应该可以让您继续下去。
The problem is this:
map sort learquivo
sort
expects a list, and somap sort
expects a list of lists ([[a]]
), whereas the type oflearquivo
is of typeFilePath -> IO [[Int]]
.You probably want something like:
There are various things in your code that could be cleaned up, but that should get you going.