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マップの代わりに使用しないでください

于 2011-11-27T23:42:13.597 に答える