以下代碼無法編譯,並顯示以下錯誤消息。 f
應該只是一個狀態monad,它在運行時創建一個帶有單個int「42」的長度爲1的向量。我懷疑一些歧義run
和unstream
之間發生的事情很像show . read
,但我無法弄清楚如何解決它:使用Data.Vector「推斷的類型不明確」錯誤
{-# LANGUAGE NoMonomorphismRestriction #-}
import Data.Vector.Generic.New (run, unstream)
import Data.Vector.Fusion.Stream (singleton)
f = run . unstream . singleton $ (42 :: Int)
main = return()
錯誤:
main.hs:6:1:
Could not deduce (Data.Vector.Generic.Base.Vector v0 Int)
arising from the ambiguity check for `f'
from the context (Data.Vector.Generic.Base.Vector v Int)
bound by the inferred type for `f':
Data.Vector.Generic.Base.Vector v Int =>
GHC.ST.ST s (Data.Vector.Generic.Base.Mutable v s Int)
at sort.hs:6:1-44
Possible fix:
add an instance declaration for
(Data.Vector.Generic.Base.Vector v0 Int)
When checking that `f'
has the inferred type `forall (v :: * -> *) s.
Data.Vector.Generic.Base.Vector v Int =>
GHC.ST.ST s (Data.Vector.Generic.Base.Mutable v s Int)'
Probable cause: the inferred type is ambiguous
main.hs:6:1:
Could not deduce (Data.Vector.Generic.Base.Mutable v0
~ Data.Vector.Generic.Base.Mutable v)
from the context (Data.Vector.Generic.Base.Vector v Int)
bound by the inferred type for `f':
Data.Vector.Generic.Base.Vector v Int =>
GHC.ST.ST s (Data.Vector.Generic.Base.Mutable v s Int)
at sort.hs:6:1-44
NB: `Data.Vector.Generic.Base.Mutable' is a type function, and may not be injective
Expected type: Data.Vector.Generic.Base.Mutable v s Int
Actual type: Data.Vector.Generic.Base.Mutable v0 s Int
Expected type: GHC.ST.ST
s (Data.Vector.Generic.Base.Mutable v s Int)
Actual type: GHC.ST.ST
s (Data.Vector.Generic.Base.Mutable v0 s Int)
When checking that `f'
has the inferred type `forall (v1 :: * -> *) s1.
Data.Vector.Generic.Base.Vector v1 Int =>
GHC.ST.ST s1 (Data.Vector.Generic.Base.Mutable v1 s1 Int)'
Probable cause: the inferred type is ambiguous