我正在学习 Purescript By Example 教程,但我无法使用左侧折叠来排列类型:
smallestFile' :: [Path] -> Maybe Path
smallestFile' (x : xs) = foldl(\acc i -> smallerFile(acc i) ) Just(x) xs // Error is on this line
smallerFile :: Maybe Path -> Path -> Maybe Path
smallerFile maybeA b = do
a <- maybeA
sa <- size a
sb <- size b
if sa > sb then return(b) else return(a)
我收到的错误在左边,是
Cannot unify Prim.Function u13116 with Data.Maybe.Maybe
我相信这些类型是一致的,但我不能对这个错误做出正面或反面。
此外,是否可以清理匿名函数语法,以便
foldl(\acc i -> smallerFile(acc i) ) Just(x) xs
变成这样:
foldl smallerFile Just(x) xs