我尝试编译以下内容:
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的任何想法?
答案 0 :(得分:6)
这里的问题是优先权。 ::
的优先级低于$
,因此将其解析为
properties <- (liftIO $ decodeFile "store") :: IO (Map String ())
而你的意思是
properties <- liftIO (decodeFile "store" :: IO (Map String ()))
答案 1 :(得分:1)
如果你使用ScopedTypeVariables,你应该这样做:
{-# LANGUAGE ScopedTypeVariables #-}
(properties :: Map String ()) <- liftIO $ decodeFile "store"
但是,您似乎只是存储密钥,为什么不使用Data.Set.Set
代替Map