haskell - 键入带有包名称和版本前缀的名称

标签 haskell happstack heist

我对 Haskell 还很陌生,我正在尝试遵循 Happstack Crash Course 。我已经完成了一些示例,但是当我尝试 the 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 安装的。

最佳答案

欢迎来到 cabal hell !发生的情况是,当您安装本示例的两个软件包 happstack-serverhappstack-heist 时,其中一个软件包引入了与另一个软件包不同的版本已经安装在您的系统上。当您尝试编译该示例时,编译器无法确定要使用哪一个。解决这个问题的方法是 sandboxes 。只需 cd 到此示例所在的目录,运行 cabal sandbox init,然后运行 ​​cabal install --dependency-only。这将获取带有 .cabal 文件的项目的所有依赖项,并将它们安装在本地 .cabal-sandbox/ 目录中。当您运行 cabal buildcabal install 时,将从该本地文件夹中提取依赖项,并且任何可执行文件都将安装在 .cabal-sandbox/bin 中>.

关于haskell - 键入带有包名称和版本前缀的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28033789/

相关文章:

parsing - Haskell 解析器到 AST

haskell - 为什么 Haskell 有底部(无限递归)?

haskell - IxSet 中的文本索引

haskell - 任何 Haskell Web 服务器都可以运行 Python CGI 应用程序吗?

haskell - Happstack 显示一个读取的文件

postgresql - 在 Heist 模板中使用 postgresql-simple 的结果

haskell - 抢夺 : why my template is not rendered?

haskell - 添加上下文以重写规则

haskell - Yesod中的超时功能