我有一个看起来像这样的 Haskell 文件:
longest::[Integer]->[Integer]->[Integer]
max a b = if length a > length b then a else b
llfs::[Integer]->Integer
llfs li = length(foldl longest group(li))
llfs([1, 2, 3, 3, 4, 5, 1, 1, 1])
应该在最后打印出函数调用的结果,但是当我运行文件时,我得到了这个错误:
parse error (possibly incorrect indentation)
我不明白我做错了什么。我应该怎么做才能修复它?
编辑
将最后一行放入 main 函数后,如下所示:
import List
longest::[Integer]->[Integer]->[Integer]
longest a b = if length a > length b then a else b
llfs::[Integer]->Integer
llfs li = length(foldl longest group(li))
main = print (llfs [1, 2, 3, 3, 4, 5, 1, 1, 1])
我现在收到以下错误:
C:\Users\Martin\Desktop\Haskell\Q1.hs:7:31:
Couldn't match expected type `[Integer]'
against inferred type `[a] -> [[a]]'
In the second argument of `foldl', namely `group'
In the first argument of `length', namely
`(foldl longest group (li))'
In the expression: length (foldl longest group (li))
这个看起来有点难度!我该如何解决?