2
我正在尝试使用箭头,并面临恼人的问题 - 我必须为我实现的所有功能提供显式类型。 如果我不能提供它GHC输出一些错误,如在haskell和箭头中的类型推断
No instance for (Arrow a0) arising from a use of ‘...’
The type variable ‘a0’ is ambiguous
我能提供明确的类型,但它是非常恼人的,因为每一次我改变了一些功能,那就是我必须手动更改类型的每个函数依赖的可能性改变。
是否可以强制ghc自动推断函数类型?
简单的情况
import Control.Arrow
ss = arr
导致
No instance for (Arrow a0) arising from a use of ‘arr’
The type variable ‘a0’ is ambiguous
Relevant bindings include
ss :: (b -> c) -> a0 b c (bound at src/Main.hs:62:1)
Note: there are several potential instances:
instance Arrow Coroutine -- Defined at src/Main.hs:33:10
instance Arrow (->) -- Defined in ‘Control.Arrow’
instance Monad m => Arrow (Kleisli m) -- Defined in ‘Control.Arrow’
In the expression: arr
In an equation for ‘ss’: ss = arr
,同时具有完全相同的语义
import Control.Arrow
ss :: forall a b c. (Arrow a) => (b -> c) -> a b c
ss = arr
代码编译得很好。
我觉得这肯定是重复的,但是我还没有发现任何其他问题,特别是来自单态限制的模糊类型错误。 – 2014-08-30 14:04:50