5

我正在尝试按照官方服务教程堆栈指南松散地使用服务和堆栈设置基本项目。一旦我添加import Servant堆栈构建失败:

Could not find module ‘Servant’
Use -v to see a list of the files searched for.

我已定义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

模块代码:

{-# 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

模块的 Cabal 定义:

library
  hs-source-dirs:      src
  exposed-modules:     API
  build-depends:       base >= 4.7 && < 5
                     , servant
                     , aeson
  default-language:    Haskell2010

我不知道我还必须在哪里定义该依赖项,以便 stack/cabal 能够获取它。

4

1 回答 1

8

Servant模块来自servant-server,您可以在模块列表中看到。方便的Servant模块重新导出了服务包中的所有内容(它具有描述 Web API 的所有类型)以及运行服务 Web 应用程序的关键内容。

长话短说:您还需要将servant-server包添加到您的依赖项中。

于 2015-09-05T16:28:52.427 回答