nah*_*mot 3 haskell ghc cabal web
我一直在尝试开始在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
Run Code Online (Sandbox Code Playgroud)
当我使用它运行时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 }
Run Code Online (Sandbox Code Playgroud)
使用cabal list text,它告诉我版本0.11.2.3和0.11.3.1已安装,但是0.11.3.1默认值.Scotty scotty.cabal指定text包必须是>= 0.11.2.3,在我看来,上面的代码应该工作.这种错误是否有任何变通方法?
错误消息
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'
Run Code Online (Sandbox Code Playgroud)
意味着你scotty是使用text软件包的0.11.2.3版本编译的,但是runhaskell的调用选择使用版本0.11.3.1(因为这是你拥有的最新版本,并且你没有告诉它使用不同的版本).Text就GHC而言,两种不同包版本的(懒惰)类型是两种完全不同的类型,因此,必须使用text用于编译scotty库的精确版本来运行代码.
runhaskell -package=text-0.11.2.3 Site.hs
Run Code Online (Sandbox Code Playgroud)
应该工作.如果您编译模块,您还需要告诉GHC text直接或通过Cabal 使用正确的版本.
另一种选择可能是scotty针对较新text版本重新编译.
| 归档时间: |
|
| 查看次数: |
369 次 |
| 最近记录: |