monad stack

14 views
Skip to first unread message

Corentin Dupont

unread,
Nov 13, 2018, 9:20:09 AM11/13/18
to haskell...@googlegroups.com
Hi guys,
I would like to run my API in this stack:

MyApp a = ReaderT AppConfig (ExceptT ServantErr IO) a

How do I need to configure the rest? I tried:

type ServerW api = ServerT api HandlerW

newtype HandlerW a = HandlerW { runHandlerW :: MyApp a }
  deriving
    ( Functor, Applicative, Monad, MonadIO, Generic
    , MonadError ServantErr
    , MonadThrow, MonadCatch
    )

type MyAPI = "api" :> "v1" :> Get '[JSON] [Perm]

server :: ServerW MyAPI
server = undefined

Is this correct?
With my attempt so far, I cannot combine different "ServerW" with the operator :<|> :

server :: ServerW MyAPI
server = Server1 :<|> Server2

       • Couldn't match type ‘ReaderT
                                 AppConfig (ExceptT ServantErr IO) ()’
                         with ‘HandlerW Token’
          Expected type: ServerW ()
            Actual type: (MyApp ())
                         :<|> (MyApp ())



Corentin Dupont

unread,
Nov 13, 2018, 9:51:56 AM11/13/18
to haskell...@googlegroups.com

Alp Mestanogullari

unread,
Nov 13, 2018, 2:53:11 PM11/13/18
to Corentin Dupont, haskell...@googlegroups.com
Yes, this page along with the tutorial section about it (https://haskell-servant.readthedocs.io/en/stable/tutorial/Server.html#using-another-monad-for-your-handlers) give you examples of using `hoistServer`, which will let you convert all the handlers from your monad to Handler, which is what servant-server knows how to serve.

Let us know here if you have any question though.

--
You received this message because you are subscribed to the Google Groups "haskell-servant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haskell-serva...@googlegroups.com.
To post to this group, send email to haskell...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/haskell-servant/CAEyhvmoFkvFXTVWMBgf2oFThNy0EUQQ6yRhuMcTCt6AWM9s8Yw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


--
Alp Mestanogullari
Reply all
Reply to author
Forward
0 new messages