我一直在尝试用斯科蒂编写一个web应用程序,但当我试图运行服务器时,我遇到了依赖冲突。这是我的密码:
{-# LANGUAGE OverloadedStrings #-}
module Site where
import Web.Scotty
import Control.Monad.IO.Class
import qualified Data.Text.Lazy.IO as T
-- Controllers
indexController :: ActionM ()
indexController = do
index <- liftIO $ T.readFile "public/index.html"
html index
routes :: ScottyM ()
routes = do
get "/" indexController
main :: IO ()
main = do
scotty 9901 routes当我使用runhaskell Site.hs运行它时,我得到以下错误:
Site.hs:12:10:
Couldn't match expected type `text-0.11.2.3:Data.Text.Lazy.Internal.Text'
with actual type `Data.Text.Lazy.Internal.Text'
In the first argument of `html', namely `index'
In a stmt of a 'do' block: html index
In the expression:
do { index <- liftIO $ T.readFile "public/index.html";
html index }使用cabal list text,它告诉我安装了0.11.2.3和0.11.3.1版本,但0.11.3.1是默认的。Scotty的scotty.cabal指定text包必须是>= 0.11.2.3,在我看来,上面的代码应该可以工作。这种错误有什么解决办法吗?
发布于 2013-07-29 14:36:20
错误信息
Site.hs:12:10:
Couldn't match expected type `text-0.11.2.3:Data.Text.Lazy.Internal.Text'
with actual type `Data.Text.Lazy.Internal.Text'这意味着您的scotty是使用text包的0.11.2.3版本编译的,但是对runhaskell的调用选择使用0.11.3.1版本(因为这是最新的版本,您还没有告诉它使用不同的版本)。对于GHC来说,两个不同包版本的(惰性) Text类型是两种完全不同的类型,因此,您必须使用text的确切版本来编译scotty库来运行代码。
runhaskell -package=text-0.11.2.3 Site.hs应该行得通。如果编译该模块,还需要告诉GHC直接或通过Cabal使用正确版本的text。
另一种选择是根据较新的scotty版本重新编译text。
https://stackoverflow.com/questions/17926608
复制相似问题