2

私は Haskell にかなり慣れていないので、Happstack Crash Courseをフォローしようとしています。いくつかの例を実行しましたが、 happstack-heist exampleを試したところ、奇妙なコンパイル エラーが発生しました。私がコンパイルしているファイルは次のようになります。

module Main where

import Control.Applicative    ((<$>))
import Control.Monad          (msum)
import qualified Data.Text    as T
import Happstack.Server       ( dir, nullConf, nullDir, simpleHTTP
                              , seeOther, toResponse
                              )
import Happstack.Server.Heist (heistServe, initHeistCompiled)
import Heist                  (Splices, (##), getParamNode, noSplices)
import Heist.Compiled         (Splice, yieldRuntimeText)
import qualified Text.XmlHtml as X

-- | factorial splice
factSplice :: (Monad m) => Splice m
factSplice = do
  intStr <- T.unpack . X.nodeText <$> getParamNode
  let res = yieldRuntimeText $ do
        case reads intStr of
          [(n,[])] ->
            return (T.pack $ show $ product [1..(n :: Integer)])
          _ ->
            return (T.pack $ "Unable to parse " ++
                    intStr ++ " as an Integer.")
  return $ res

main :: IO ()
main = do
  heistState <- do
    r <- initHeistCompiled (T.pack "fact" ## factSplice) noSplices "."
    case r of
      (Left e) -> error $ unlines e
      (Right heistState) -> return $ heistState
  simpleHTTP nullConf $ msum
    [ dir "heist" $ heistServe heistState
    , nullDir >>
      seeOther "/heist/factorial" (toResponse "/heist/factorial")
    ]

エラーは次のとおりです。

test.hs:37:36:
    Couldn't match expected type `happstack-server-7.3.9:Happstack.Server.Internal.Types.Response'
                with actual type `Happstack.Server.Internal.Types.Response'
    In the return type of a call of `toResponse'
    In the second argument of `seeOther', namely
      `(toResponse "/heist/factorial")'
    In the second argument of `(>>)', namely
      `seeOther "/heist/factorial" (toResponse "/heist/factorial")'

パッケージ名とバージョン番号を前に付けた型が必要なようですが、わかりません。happstack-server と happstack-heist の両方が でインストールされましたcabal install

4

1 に答える 1

3

カバル地獄へようこそ!happstack-serverこの例のとの 2 つのパッケージをインストールしたときにhappstack-heist、そのうちの 1 つが、システムに既にインストールされているものとは異なるバージョンの を取り込みました。例をコンパイルしようとしたとき、コンパイラはどれを使用するかを判断できませんでした。これに対する解決策はサンドボックスです。この例cdがあるディレクトリに移動し、 を実行cabal sandbox initしてからcabal install --dependencies-only. これにより、ファイルを使用してプロジェクトのすべての依存関係が取得.cabalされ、ローカル.cabal-sandbox/ディレクトリにインストールされます。を実行するcabal buildcabal install、このローカル フォルダーから依存関係を取得すると、実行可能ファイルが にインストールされ.cabal-sandbox/binます。

于 2015-01-19T21:53:00.627 に答える