Haskell依赖冲突

时间:2013-07-29 14:25:54

标签: haskell web ghc cabal

我一直在尝试在Scotty中开始编写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.30.11.3.1,但0.11.3.1是默认设置。 Scotty的scotty.cabal指定text包必须是>= 0.11.2.3,在我看来,上面的代码应该可行。是否存在此类错误的解决方法?

1 个答案:

答案 0 :(得分:5)

错误消息

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的确切版本1}}库来运行代码。

scotty

应该工作。如果您编译模块,您还需要告诉GHC直接或通过Cabal使用正确版本的runhaskell -package=text-0.11.2.3 Site.hs

另一种选择可能是针对较新的text版本重新编译scotty

相关问题