天道酬勤,学无止境

haskell-wai

How do I use wai-handler-devel with a simple wai application

I have the basic "hello world" application setup using wai, and would like to use wai-handler-devel, but am unsure how to go about it and can't find any examples of it in usage on a wai project. {-# LANGUAGE OverloadedStrings #-} import Network.Wai import Network.HTTP.Types import Network.Wai.Handler.Warp (run) import Data.ByteString.Lazy.Char8 () -- Just for an orphan instance app :: Application app _ = return $ responseLBS status200 [("Content-Type", "text/plain")] "Hello, World!" main :: IO () main = do putStrLn $ "http://localhost:8080/" run 8080 app What do I need to do to get wai-handler

2021-06-09 17:50:33    分类:问答    haskell   yesod   haskell-wai

Scotty:连接池作为monad读取器(Scotty: connection pool as monad reader)

问题 包括读者在内,有成千上万的monad教程,当您阅读它时,一切似乎都很清楚。 但是,当您实际需要编写时,情况就大不一样了。 我从未使用过Reader,只是在实践中从未接触过它。 因此,尽管我已阅读有关内容,但我仍不知道该如何处理。 我需要在Scotty中实现一个简单的数据库连接池,以便每个操作都可以使用该池。 该池必须是“全局”的,并且可由所有操作功能访问。 我读到,做到这一点的方法是Reader monad。 如果还有其他方法,请通知我。 您能否帮助我,并说明如何使用Reader正确执行此操作? 如果我通过自己的示例看到它是如何完成的,则可能会学得更快。 {-# LANGUAGE OverloadedStrings #-} module DB where import Data.Pool import Database.MongoDB -- Get data from config ip = "127.0.0.1" db = "index" --Create the connection pool pool :: IO (Pool Pipe) pool = createPool (runIOE $ connect $ host ip) close 1 300 5 -- Run a database action with connection pool run

2021-04-30 20:54:51    分类:技术分享    haskell   scotty   haskell-wai

Scotty: connection pool as monad reader

There are trillions of monad tutorial including the reader and it seems all clear when you read about it. But when you actually need to write, it becomes a different matter. I'v never used the Reader, just never got to it in practice. So I don't know how to go about it although I read about it. I need to implement a simple database connection pool in Scotty so every action can use the pool. The pool must be "global" and accessible by all action functions. I read that the way to do it is the Reader monad. If there are any other ways please let me know. Can you please help me and show how to do

2021-04-14 01:25:43    分类:问答    haskell   scotty   haskell-wai