我是 Haskell 的初学者,我正在尝试将一个列表分成两个大小大致相等的子列表。该模块可以加载,但是当我尝试运行 ghci 时,它不起作用。
例如:divideList [1,2,3,4] = [1,2] [3,4] divideList [1,2,3,4,5] = [1,2,3] [4,5]
divideList [] = ([],[])
divideList [x] = ([x],[])
divideList ((x:xs):ys) = if a < b
then splitAt (a+1) ((x:xs):ys)
else divideList (xs:ys)
where a = length xs
b = length ys
它说“没有(Num [t0])的实例来自文字'2'”。我不知道如何解决它。谁能帮我???谢谢!
这是我在 ghci 中输入 divideList [2,3,5] 时显示的错误。
<interactive>:2:13:
No instance for (Num[a0]) arising from literal '2'
Possible fix: add an instance declaration for (Num[a0])
In the expression: 2
In the first argument of 'divideList', namely "[2,3,5]
In the expression: divideList [2,3,5]