2012-07-31 46 views
1

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") 

但似乎醜陋的我。

回答

1

您可以使用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