haskell-servant / servant

Servat is a Haskell DSL for describing, serving, querying, mocking, documenting web applications and more!
https://docs.servant.dev/
1.82k stars 411 forks source link

Error on `cabal new-repl tutorial` #1291

Open ghost opened 4 years ago

ghost commented 4 years ago

I'm following https://haskell-servant.readthedocs.io/en/stable/tutorial/index.html, and getting this message when running cabal new-repl tutorial. The error suggests editing the files, but I'm reluctant to do that. I assume there's something else wrong.

$ cabal new-repl tutorial
Build profile: -w ghc-8.8.3 -O0
In order, the following will be built (use -v for more details):
 - tutorial-0.10 (lib) (ephemeral targets)
Preprocessing library for tutorial-0.10..
GHCi, version 8.8.3: https://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from ...servant/doc/tutorial/.ghci
[1 of 6] Compiling ApiType          ( ApiType.lhs, interpreted )
[2 of 6] Compiling Authentication   ( Authentication.lhs, interpreted )

Authentication.lhs:50:1: error: [-Wunused-imports, -Werror=unused-imports]
    The import of ‘Data.Monoid’ is redundant
      except perhaps to import instances from ‘Data.Monoid’
    To import instances alone, use: import Data.Monoid()
   |
50 | import Data.Monoid                      ((<>))
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Failed, one module loaded.
*ApiType> 

cabal is version 3.2.0.0

dmjio commented 4 years ago

We might need to use CPP to conditionally import Data.Monoid, or opt for something like base-compat. In the meantime, you might be able to get away with > :unset -Wall and then > :r

erewok commented 4 years ago

@dmjio, following your suggestion, this seems to work on 8.8.3 (but I didn't know the actual version to branch on...):

❯ git diff
diff --git a/doc/tutorial/Authentication.lhs b/doc/tutorial/Authentication.lhs
index aa339d54..affdb3b8 100644
--- a/doc/tutorial/Authentication.lhs
+++ b/doc/tutorial/Authentication.lhs
@@ -31,6 +31,7 @@ data BasicAuth (realm :: Symbol) (userData :: *)
 You can use this combinator to protect an API as follows:

 ```haskell
+{-# LANGUAGE CPP                   #-}
 {-# LANGUAGE DataKinds             #-}
 {-# LANGUAGE DeriveGeneric         #-}
 {-# LANGUAGE FlexibleContexts      #-}
@@ -47,7 +48,9 @@ module Authentication where
 import Data.Aeson                       (ToJSON)
 import Data.ByteString                  (ByteString)
 import Data.Map                         (Map, fromList)
+#if (__GLASGOW_HASKELL__ < 802)
 import Data.Monoid                      ((<>))
+#endif
 import qualified Data.Map            as Map
 import Data.Proxy                       (Proxy (Proxy))
 import Data.Text                        (Text)
danilbraun commented 3 years ago

We might need to use CPP to conditionally import Data.Monoid, or opt for something like base-compat. In the meantime, you might be able to get away with > :unset -Wall and then > :r

*ApiType> :unset -Wall
don't know how to reverse -Wall