在 Yesod 处理程序中使用 Data.Binary.decodeFile

发布于 2024-12-17 17:32:47 字数 719 浏览 3 评论 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 的任何想法?

I tried to compile the following:

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

but I got the following compiler error:

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

Any ideas on how I use Data.Binary.decodeFile in a Yesod handler?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

成熟的代价 2024-12-24 17:32:47

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

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

您的意思是

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

The problem here is precedence. :: has lower precedence than $, so this parses as

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

while what you meant was

properties <- liftIO (decodeFile "store" :: IO (Map String ()))
丢了幸福的猪 2024-12-24 17:32:47

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

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

但是,看起来你只是存储键,为什么不使用 Data.Set.Set 而不是 Map

if you use ScopedTypeVariables, and you should, you can do this:

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

But, it seems like you're just storing Keys, why dont you use Data.Set.Set instead of Map

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文