簡體   English   中英

無法修復Aeson和Spock中的“歧義類型變量”

[英]Unable to fix “Ambiguous type variable” in Aeson and Spock

我有一個Spock應用程序,其中有:

    post "/test" $ do
        a <- jsonBody'
        text "test"

它引發異常:

• Ambiguous type variable ‘a0’ arising from a use of ‘jsonBody'’
      prevents the constraint ‘(Aeson.FromJSON a0)’ from being solved.
      Probable fix: use a type annotation to specify what ‘a0’ should be.
      These potential instances exist:
        instance Aeson.FromJSON Aeson.DotNetTime

因此,我試圖像這樣解決它:

post "/test" $ do
        a <- jsonBody' :: Aeson.Object
        text "test" 

但沒有運氣:

• Couldn't match type ‘ActionCtxT
                             () (WebStateM () MySession MyAppState) ()’
                     with ‘unordered-containers-0.2.8.0:Data.HashMap.Base.HashMap
                             T.Text b0’
      Expected type: hvect-0.4.0.0:Data.HVect.HVectElim
                       '[] (SpockActionCtx () () MySession MyAppState ())
        Actual type: unordered-containers-0.2.8.0:Data.HashMap.Base.HashMap
                       T.Text b0

如何解決?

更新:

這不能解決問題:

        a <- jsonBody' :: Aeson.Object
        --a :: Aeson.Object <- jsonBody'
        let b = show a -- using a
        text "fdsfd" 

a <- jsonBody' :: Aeson.ObjectAeson.Object作為jsonBody'的簽名。 但這是行不通的: jsonBody'不是值,而是從中獲取該值的操作 您可能希望將該簽名提供a

{-# LANGUAGE ScopedTypeSignatures #-}

post "/test" $ do
    a :: Aeson.Object <- jsonBody'
    text "test"

真的,你也許並不需要這樣的東西雖然-只要確保你實際使用的 a ,那么編譯器將可能是能夠找出它的類型自身!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM