我正在尝试按照官方服务教程和堆栈指南松散地使用服务和堆栈设置基本项目。一旦我添加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 能够获取它。