haskell - Using servant with ReaderT IO a -


i'm using servant library json api. need servert myapi (readert io) monad stack working.

here's example using readert, without integrating servant:

-- code works  type testapi =          "a" :> '[json] string     :<|> "b" :> '[json] string  test2 :: eithert servanterr io string test2 = return "asdf"  testserver :: int -> server testapi testserver code = test :<|> test2       test :: eithert servanterr io string     test = liftio $ runreadert (givemeamessage) code  -- contrived. in real application want use reader database connection.  givemeamessage :: readert int io string givemeamessage =     code <- ask     name <- liftio $ getprogname     return $ show code <> name 

so, working servert, following example in this article.

-- code doesn't compile   testservert :: servert testapi (readert int io) testservert = test :<|> test        test :: eithert servanterr (readert int io) string     test = lift $ givemeamessage  testserver' :: int -> server testapi testserver' code = enter (nat $ liftio . (`runreadert` code)) testservert 

i following error:

server/serials/route/test.hs:43:15:     couldn't match type ‘eithert servanterr (readert int io) string’                   ‘readert int io [char]’     expected type: servert testapi (readert int io)       actual type: eithert servanterr (readert int io) string                   :<|> eithert servanterr (readert int io) string     in expression: test :<|> test     in equation ‘testservert’:         testservert           = test :<|> test                         test :: eithert servanterr (readert int io) string               test = lift $ givemeamessage failed, modules loaded: none. 

how can rid of error?

followup question: understand monad transformers generally, i'm lost. topics or links should study know enough answer own question?

you there, test should be:

test :: readert int io string test = givemeamessage 

as other questions, don't have time answer servant developers should make easier or better documented.

could please read through source whichever part confuses you, , ask specific questions?


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -