我对 Haskell 很陌生,我正在尝试跟随Happstack Crash Course。我已经完成了一些示例,但是当我尝试happstack-heist 示例时,我得到了一个奇怪的编译错误。我正在编译的文件如下所示:
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
.