Partial type signature
Possible Duplicate:
Incomplete type signature
Consider the following:
import Network.HTTP.Conduit
(parseUrl "http://stackoverflow.com") :: Maybe a
parseUrl
returns Failure HttpException m => m (Request m')
It's documentation says:
Since this function uses Failure
, the return monad can be anything that is an instance of Failure
, such as IO
or Maybe
.
However, when I try to force parseUrl
to use Maybe
, I get the following error:
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)
Is there anyway to force the type to Maybe
without specifying the full exact type? Answers including GHC extensions are fine.
Note that this works:
f :: Maybe a -> Maybe a
f x = x
f (parseUrl "http://stackoverflow.com")
But it seems ugly to me.
You can use asTypeOf
,
main = do
print (parseUrl "http://stackoverflow.com" `asTypeOf` Nothing)
to force the monad to be Maybe
. Not that that gains much over
main = do
print (parseUrl "http://stackoverflow.com" :: Maybe (Request m))
链接地址: http://www.djcxy.com/p/7450.html
上一篇: 你可以部分限制Haskell中的类型吗?
下一篇: 部分类型签名