我正在尝试遵循仆人教程,但遇到了 Cabal 错误Unknown fields: build-tool-depends
。这是我的tutorial.cabal
文件(我从仆人的 github repo得到这个):
name: tutorial
version: 0.10
synopsis: The servant tutorial
homepage: http://haskell-servant.readthedocs.org/
license: BSD3
license-file: LICENSE
author: Servant Contributors
maintainer: haskell-servant-maintainers@googlegroups.com
build-type: Simple
cabal-version: >=1.10
library
exposed-modules: Server
build-depends: base == 4.*
, base-compat
, text
, aeson
, aeson-compat
, blaze-html
, directory
, blaze-markup
, containers
, servant == 0.11.*
, servant-server == 0.11.*
, servant-client == 0.11.*
, servant-docs == 0.11.*
, servant-js >= 0.9 && <0.10
, warp
, http-api-data
, http-media
, lucid
, time
, string-conversions
, bytestring
, attoparsec
, mtl
, random
, js-jquery
, wai
, http-types
, transformers
, markdown-unlit >= 0.4
, http-client
default-language: Haskell2010
ghc-options: -Wall -pgmL markdown-unlit
build-tool-depends: markdown-unlit:markdown-unlit
test-suite spec
type: exitcode-stdio-1.0
ghc-options: -Wall
default-language: Haskell2010
hs-source-dirs: test
main-is: Spec.hs
other-modules: JavascriptSpec
build-depends: base == 4.*
, tutorial
, hspec
, hspec-wai
, string-conversions
应该cabal build
可以建这个吧?这是我得到的输出:
➜ servant cabal build
Package has never been configured. Configuring with default flags. If this
fails, please run configure manually.
Warning: tutorial.cabal: Unknown fields: build-tool-depends (line 46)
Fields allowed in this section:
...
cabal --version
给出:
cabal-install version 1.24.0.2
compiled using version 1.24.2.0 of the Cabal library
我不认为我的ApiType.hs
文件对这个错误很重要,但这里以防万一:
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
module Server where
import Prelude ()
import Prelude.Compat
import Control.Monad.Except
import Control.Monad.Reader
import Data.Aeson.Compat
import Data.Aeson.Types
import Data.Attoparsec.ByteString
import Data.ByteString (ByteString)
import Data.List
import Data.Maybe
import Data.String.Conversions
import Data.Time.Calendar
import GHC.Generics
import Lucid
import Network.HTTP.Media ((//), (/:))
import Network.Wai
import Network.Wai.Handler.Warp
import Servant
import System.Directory
import Text.Blaze
import Text.Blaze.Html.Renderer.Utf8
import qualified Data.Aeson.Parser
import qualified Text.Blaze.Html
type UserAPI =
"users" :> Get '[JSON] [User]
-- :<|> "user" :> Capture "id" Integer :> Get '[JSON] User
-- :<|> "user" :> ReqBody '[JSON] User :> Post '[JSON] User
data User = User {
id :: Int,
name :: String,
age :: Int,
email :: String,
registration_date :: UTCTime
}
instance ToJSON User
users1 :: [User]
users1 =
[ User 1 "Isaac Newton" 372 "isaac@newton.co.uk" (fromGregorian 1683 3 1)
, User 2 "Albert Einstein" 136 "ae@mc2.org" (fromGregorian 1905 12 1)
]
server1 :: Server UserAPI
server1 = return users1
userAPI :: Proxy UserAPI
userAPI = Proxy
app1 :: Application
app1 = serve userAPI server1
main :: IO ()
main = run 8081 app1
非常欢迎任何帮助!