部分类型签名

问题描述:

Possible Duplicate:
Incomplete type signature部分类型签名

考虑以下几点:

import Network.HTTP.Conduit 

(parseUrl "http://stackoverflow.com") :: Maybe a 

parseUrl回报Failure HttpException m => m (Request m')

它的文件说:

Since this function uses Failure , the return monad can be anything that is an instance of Failure , such as IO or Maybe .

然而,当我试图迫使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") 

但似乎丑陋的我。

您可以使用asTypeOf

main = do 
    print (parseUrl "http://stackoverflow.com" `asTypeOf` Nothing) 

迫使单子是Maybe。并不是说这个收益大大超过

main = do 
    print (parseUrl "http://stackoverflow.com" :: Maybe (Request m)) 
+0

我已经问过关于这个更好的问题http://stackoverflow.com/questions/11751318/incomplete-type-signature – Clinton 2012-08-01 01:23:28