简体   繁体   中英

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?

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]]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM