2013-07-29 57 views
3

我一直在尝试开始编写Scotty中的Web应用程序,但是当我尝试运行服务器时,出现依赖关系冲突。这里是我的代码:Haskell依赖冲突

{-# 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,在我看来,上面的代码应该可以工作。这种错误是否有任何解决方法?

回答

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的精确版本来编译scotty库以运行代码。

runhaskell -package=text-0.11.2.3 Site.hs 

应该工作。如果你编译模块,你还需要告诉GHC直接或通过Cabal使用正确版本的text

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

+0

太棒了!有没有办法在全球范围内设置默认包? – nahiluhmot

+0

不,不是。默认情况下使用最新版本(如最高版本号所示)。你可以隐藏你不想使用的版本,'ghc-pkg hide foo-0.1.2.3',然后GHC将不会使用该版本,除非你明确告诉它。所以隐藏所有较新的版本是使某个版本成为默认版本。 –