开发者

Haskell frustration with function calls

Learning Haskell is killing me. If I am going to write a function that takes an array of arrays of order-able elements, and outputs the same thing, how do I do that?

开发者_C百科I try:

main = testfn [[1],[2]]

testfn :: (Ord a) => [[a]] -> [[a]]
testfn x = x

But the message I get is:

Couldn't match expected type 'IO t0' with actual type '[[a0]]' In the expression: main When checking the type of the function 'main'


Your problem here is that main must be of a type of the form IO a (you can see this in the error - GHC is expecting main's inferred type [[a0]] to match against IO t0). Here main has type [[Int]]. You can easily fix this by simply printing the result:

main = print (testfn [[1],[2]])


The function main must have type IO a. You are defining main as testfn [..] which is of type Ord a, Num a => [[a]].

What do you want the program to do? Compare to a known solution for your ordering?

main = print (knownSolution == testfn [[1],[2]])

Or perhaps print the result?

main = print $ testfn [[1],[2]]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜