以包名称和版本为前缀的类型名称
Type names prefixed with package name and version
我是 Haskell 的新手,我正在尝试跟进 Happstack Crash Course. I've done some of the examples, but when I tried 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
.
欢迎来到阴谋地狱!发生的事情是,当您为此示例安装两个包 happstack-server
和 happstack-heist
时,其中一个引入了与您系统上已安装版本不同的另一个版本。当您尝试编译该示例时,编译器无法确定要使用哪一个。解决方案是 sandboxes。只需 cd
到您有此示例的目录,运行 cabal sandbox init
,然后 cabal install --dependencies-only
。这将使用 .cabal
文件获取项目的所有依赖项并将它们安装在本地 .cabal-sandbox/
目录中。当您 运行 cabal build
或 cabal install
从该本地文件夹中提取依赖项时,任何可执行文件都将安装在 .cabal-sandbox/bin
.
中
我是 Haskell 的新手,我正在尝试跟进 Happstack Crash Course. I've done some of the examples, but when I tried 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
.
欢迎来到阴谋地狱!发生的事情是,当您为此示例安装两个包 happstack-server
和 happstack-heist
时,其中一个引入了与您系统上已安装版本不同的另一个版本。当您尝试编译该示例时,编译器无法确定要使用哪一个。解决方案是 sandboxes。只需 cd
到您有此示例的目录,运行 cabal sandbox init
,然后 cabal install --dependencies-only
。这将使用 .cabal
文件获取项目的所有依赖项并将它们安装在本地 .cabal-sandbox/
目录中。当您 运行 cabal build
或 cabal install
从该本地文件夹中提取依赖项时,任何可执行文件都将安装在 .cabal-sandbox/bin
.