学习Haskell杀死了我。如果我要编写一个函数,该函数采用可排序元素数组的数组并输出相同的内容,该怎么做?
我尝试:
main = testfn [[1],[2]]
testfn :: (Ord a) => [[a]] -> [[a]]
testfn x = x
但是我得到的消息是:
Couldn't match expected type 'IO t0' with actual type '[[a0]]' In the expression: main When checking the type of the function 'main'
最佳答案
您的问题是main
必须是IO a
形式的类型(您可以在错误中看到这一点-GHC期望main的推断类型[[a0]]
与IO t0
匹配)。此处main
的类型为[[Int]]
。您只需打印结果即可轻松解决此问题:
main = print (testfn [[1],[2]])
关于list - Haskell对函数调用感到沮丧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7476285/