可能重复:
不完整的类型签名
考虑以下:
import Network.HTTP.Conduit
(parseUrl "http://stackoverflow.com") :: Maybe a
parseUrl
返回Failure HttpException m => m (Request m')
它的文档说:
由于此函数使用
Failure
,因此返回单子可以是任何 的实例Failure
,例如IO
orMaybe
。
但是,当我尝试强制parseUrl
使用Maybe
时,出现以下错误:
main.hs:9:11:
Couldn't match type `a' with `Request m'0'
`a' is a rigid type variable bound by
an expression type signature: Maybe a at main.hs:9:10
Expected type: Maybe a
Actual type: Maybe (Request m'0)
无论如何强制类型Maybe
而不指定完整的确切类型?包括 GHC 扩展在内的答案都很好。
请注意,这有效:
f :: Maybe a -> Maybe a
f x = x
f (parseUrl "http://stackoverflow.com")
但这对我来说似乎很丑。