我是一个Haskell新手,和GHCi一起工作,版本为7.6.3
我试图理解为什么这个函数分配(或替换,无论是什么正确的术语)不起作用。
此代码运行良好:
import qualified Data.List as L
testSort list = L.sort list迅速:
*Main> testSort [3,2,1]
[1,2,3]但是,如果我删除了像这样的列表参数.
import qualified Data.List as L
testSort = L.sort对我来说,这很直观,这将简单地替代L.sort来代替testSort,然后我就可以像以前一样在提示符下运行相同的命令并得到相同的结果。但是,我从GHCi中得到了一个很大的错误:
No instance for (Ord a0) arising from a use of `L.sort'
The type variable `a0' is ambiguous
Possible cause: the monomorphism restriction applied to the following:
testSort :: [a0] -> [a0] (bound at modulesandbox.hs:4:1)
Probable fix: give these definition(s) an explicit type signature
or use -XNoMonomorphismRestriction
Note: there are several potential instances:
instance Integral a => Ord (GHC.Real.Ratio a)
-- Defined in `GHC.Real'
instance Ord () -- Defined in `GHC.Classes'
instance (Ord a, Ord b) => Ord (a, b) -- Defined in `GHC.Classes'
...plus 23 others
In the expression: L.sort
In an equation for `testSort': testSort = L.sort是否有一种方法来设置我的代码,以便testSort = L.sort可以作为一个简单的函数替换?
发布于 2015-01-06 08:22:34
https://stackoverflow.com/questions/27794660
复制相似问题