Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the reader monad in snap (or, monad transformers in snap)

Can someone show how to use the snap monad inside the reader monad? Monad transformers confuse me. (Alternatively, I will gladly accept suggestions of tutorials about monad transformers, and ways to see the light and finally grok them.)

Edit: Oops; forgot to specify what I'm actually trying to do, instead of asking for help with a specific thing. Strategy, not tactics. I specifically want to share a database connection/pool amongst all handlers, without having to explicitly pass that database connection/pool when specifying routes. It seems that the reader monad would be the way to accomplish that.

like image 244
heartpunk Avatar asked Jan 21 '23 13:01

heartpunk


1 Answers

Snap has ApplicationState type that allows you package whatever application wide resources you need (db connections, template engines etc.)

It is located in generated file Application.hs and by default has HeistState and TimerState included into ApplicationState. You can just put your db connection there and it will be available from anywhere in your Snap application.

like image 97
Vagif Verdi Avatar answered Feb 17 '23 06:02

Vagif Verdi