2

Is it possible to specify which instance is overlapping and which instance is overlappable with ghc 7.8 OverlappingInstances?

I am trying to make some updates/changes in the servant/servant-server packages. Everything compiles fine and all test pass except one doctest which was passing before I added this change Enter instance for Raw. The doctest only fails on ghc 7.8, and passes on ghc 7.10. I believe this is related to the fact that ghc 7.10 I can specify which instance is overlapping and which instance is overlappable. How can I accomplish this is ghc 7.8? Any ideas/pointers would be greatly appreciated. Here is the doctest and failing error I am getting on ghc 7.8:

-- >>> import Control.Monad.Reader
-- >>> import qualified Control.Category as C
-- >>> type ReaderAPI = "ep1" :> Get '[JSON] Int :<|> "ep2" :> Get '[JSON] String
-- >>> let readerServer = return 1797 :<|> ask :: ServerT ReaderAPI (Reader String)
-- >>> let mainServer = enter (generalizeNat C.. (runReaderTNat "hi")) readerServer :: Server ReaderAPI
--

-- $setup
-- >>> import Servant.API
-- >>> import Servant.Server

-- Error
### Failure in src/Servant/Server.hs:129: expression `let mainServer = enter (generalizeNat C.. (runReaderTNat "hi")) readerServer :: Server ReaderAPI'
expected:
but got:
          <interactive>:44:18:
              Couldn't match type ‘Control.Monad.Trans.Either.EitherT
                                     ServantErr IO [Char]’
                            with ‘ReaderT String Data.Functor.Identity.Identity [Char]’
              In the expression:
                  enter (generalizeNat C.. (runReaderTNat "hi")) readerServer ::
                    Server ReaderAPI
              In an equation for ‘mainServer’:
                  mainServer
                    = enter (generalizeNat C.. (runReaderTNat "hi")) readerServer ::
                        Server ReaderAPI
codedmart
  • 107
  • 2
  • 8
  • The overlapping/overlappable thing is 7.10 only. I don't know what's causing your problem, but you might be able to solve it by not using overlapping instances. – dfeuer Aug 18 '15 at 21:40
  • 2
    Also, `MIN_VERSION_base` isn't really a sane way to check for GHC features. Use `__GLASGOW_HASKELL__ >= 710` instead. Check the base library version only to check if the base library is what you need. – dfeuer Aug 18 '15 at 21:46
  • @dfeuer you mean not using overlapping instances by rewriting the instances so I don't need overlapping? – codedmart Aug 19 '15 at 01:12
  • I'm not yet convinced that they're actually a good idea. They can make for pretty APIs, but they feel limited in odd ways. – dfeuer Aug 19 '15 at 01:52

1 Answers1

0

This is not possible with OverlappingInstances in 7.8. Need to rewrite instances so there is no need for the OverlappingInstances pragma.

codedmart
  • 107
  • 2
  • 8