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