Why not `MonadDatabase`? - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Sridhar Ratnakumar

The 3layer blog posts says:

DO NOT try to implement MonadRedis or MonadDatabase or MonadFilesystem here.

Yet when you look at the holmusk app, it does use something like MonadDatabase (i.e., WithDb): https://github.com/Holmusk/three-layer/blob/1b58ec102f206681b66a584ca4a7d18f2eb4ef81/src/Lib/Db/User.hs#L15-L20

It's WithDb itself is based on the Has pattern: https://haskell.zettel.page/a997bfa5.html

How would you one do this so as to make it testable?

:three: :cake: Architecture of the Haskell web applications - Holmusk/three-layer
Fintan Halpenny

I think the idea there would be that your Monad is specific for getting a user

Fintan Halpenny

The implementation is using the DB

Fintan Halpenny

Keep your scope concentrated on your business logic. The DB just helps you execute that logic

Sridhar Ratnakumar

@Fintan Halpenny Would you say, then, that Holmusk/three-layer is a bad example? Because its getUserByEmail requires WithDb (which is specific to database), and you cannot test any of its business logic that uses this function (eg: what loginHandler does)

Fintan Halpenny

Ya withDb is constrained to MonadIO so it makes it harder to test

Fintan Halpenny

I forget the 3-layer method but I certainly would say that it's not a great example of separation :)

Sridhar Ratnakumar

Jesus, this mtl thing is so fscking confusin. Wish I could use something neater like polysemy.

Sridhar Ratnakumar

And what is this MonadBaseControl. Fsck

Fintan Halpenny

I just glanced back at Matt's post. He has a pretty clear example of scoping the typeclass to just User functions

Fintan Halpenny

MonadBaseControl comes into play when you're working with resources and IO and I've mostly cargo culted it in the past :sweat_smile:

Sridhar Ratnakumar

I was trying to use that di library (because I thought hierarhical logging is cool), and it used MonadMask, MonadBaseControl and all that jazz, whereas this app uses MonadSnap and I just gave up making them all behave well together

Sridhar Ratnakumar

Anyway, I'm giving up, and trying polysemy. Giving it an actual chance finally.

Sridhar Ratnakumar

I think polysemy embraces Boring Haskell more than mtl (in a philosophical sense).