0

我试图编译以下内容:

postRQuery :: Handler RepHtml
postRQuery = do
 properties <- liftIO $ decodeFile "store" :: IO (Map String ())
 defaultLayout [whamlet|Posted!|]

但我收到以下编译器错误:

Couldn't match expected type `GGHandler
                              Bayith
                              Bayith
                              (Data.Enumerator.Iteratee
                               Data.ByteString.Internal.ByteString IO)
                              t0'
        with actual type `IO (Map String ())'
In a stmt of a 'do' expression:
    properties <- liftIO $ decodeFile "store" :: IO (Map String ())

关于如何在 Yesod 处理程序中使用 Data.Binary.decodeFile 的任何想法?

4

2 回答 2

6

这里的问题是优先级。::的优先级低于$,因此解析为

properties <- (liftIO $ decodeFile "store") :: IO (Map String ())

而你的意思是

properties <- liftIO (decodeFile "store" :: IO (Map String ()))
于 2011-11-22T17:40:21.657 回答
1

如果你使用 ScopedTypeVariables,你应该这样做,你可以这样做:

{-# LANGUAGE ScopedTypeVariables #-}
(properties :: Map String ()) <- liftIO $ decodeFile "store"

但是,您似乎只是在存储密钥,为什么不使用Data.Set.Set而不是 Map

于 2011-11-27T23:42:13.597 回答