无法使用堆栈设置servant应用程序 - "无法找到模块'Servant'"

mcv*_*eat 5 haskell haskell-stack

我正在尝试使用servant和堆栈松散地设置基本项目,遵循官方仆人教程堆栈指南.一旦我添加import Servant堆栈构建失败:

Could not find module ‘Servant’
Use -v to see a list of the files searched for.
Run Code Online (Sandbox Code Playgroud)

我已经定义servant为此模块的依赖项,并且堆栈注意到它stack dependencies显示为:

aeson 0.8.0.2
array 0.5.1.0
attoparsec 0.12.1.6
base 4.8.1.0
binary 0.7.5.0
blaze-builder 0.4.0.1
bytestring 0.10.6.0
bytestring-conversion 0.3.1
case-insensitive 1.2.0.4
containers 0.5.6.2
deepseq 1.4.1.1
dlist 0.7.1.2
double-conversion 2.0.1.0
ghc-prim 0.4.0.0
hashable 1.2.3.3
http-media 0.6.2
http-types 0.8.6
integer-gmp 1.0.0.0
mtl 2.2.1
network-uri 2.6.0.3
parsec 3.1.9
primitive 0.6
scientific 0.3.3.8
servant 0.4.4.2
string-conversions 0.4
syb 0.5.1
template-haskell 2.10.0.0
text 1.2.1.3
tforia-products 0.1.0.0
time 1.5.0.1
transformers 0.4.2.0
unordered-containers 0.2.5.1
utf8-string 1.0.1.1
vector 0.10.12.3
Run Code Online (Sandbox Code Playgroud)

模块代码:

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}

module API
    ( ProductAPI
    , apiServer
    ) where

import Data.Aeson
import GHC.Generics
import Servant

data Product = Product
  { id :: String
  , name :: String
  } deriving (Eq, Show, Generic)

instance ToJSON Product

products :: [Product]
products =
  [ Product "id123" "shoes of some guy"
  , Product "id234" "hat of some gal"
  ]

type ProductAPI = "products" :> Get '[JSON] [Product]

apiServer :: Server UserAPI
apiServer = return products
Run Code Online (Sandbox Code Playgroud)

模块的Cabal定义:

library
  hs-source-dirs:      src
  exposed-modules:     API
  build-depends:       base >= 4.7 && < 5
                     , servant
                     , aeson
  default-language:    Haskell2010
Run Code Online (Sandbox Code Playgroud)

我不知道我还有什么地方可以定义那个依赖,所以stack/cabal能够把它拿起来.

Alp*_*ari 8

Servant模块来自仆人服务器,你可以看到这里的模块列表.这个方便的Servant模块重新导出servant包中的所有内容(包含描述Web API的所有类型)以及运行servant Web应用程序的关键内容.

简而言之:您还需要将servant-server软件包添加到依赖项中.