这是我对任何函数的定义
any' :: (t -> Bool) -> [t] -> Bool
any' f = foldl' step False
where step :: Bool -> t -> Bool
step b x | f x = True
| otherwise = b
加载拥抱时出现此错误:
ERROR "folds.hs":65 - Inferred type is not general enough
*** Expression : step
*** Expected type : Bool -> a -> Bool
*** Inferred type : Bool -> _7 -> Bool
...这在 ghci 中:
folds.hs:65:27:
Couldn't match expected type `t' with actual type `t1'
`t' is a rigid type variable bound by
the type signature for any' :: (t -> Bool) -> [t] -> Bool
at folds.hs:62:9
`t1' is a rigid type variable bound by
the type signature for step :: Bool -> t1 -> Bool at folds.hs:64:22
In the first argument of `f', namely `x'
In the expression: f x
In a stmt of a pattern guard for
an equation for `step':
f x
当我删除 step 的类型定义时它工作正常,所以我的问题是......有一种方法可以正确编写该类型定义,还是我正在处理无法显式键入本地函数的情况之一?