@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)
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
The 3layer blog posts says:
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.htmlHow would you one do this so as to make it testable?
I think the idea there would be that your Monad is specific for getting a user
The implementation is using the DB
Keep your scope concentrated on your business logic. The DB just helps you execute that logic
@Fintan Halpenny Would you say, then, that Holmusk/three-layer is a bad example? Because its
getUserByEmail
requiresWithDb
(which is specific to database), and you cannot test any of its business logic that uses this function (eg: whatloginHandler
does)Ya
withDb
is constrained toMonadIO
so it makes it harder to testI forget the 3-layer method but I certainly would say that it's not a great example of separation :)
Jesus, this mtl thing is so fscking confusin. Wish I could use something neater like polysemy.
And what is this
MonadBaseControl
. FsckI just glanced back at Matt's post. He has a pretty clear example of scoping the typeclass to just User functions
MonadBaseControl
comes into play when you're working with resources andIO
and I've mostly cargo culted it in the past :sweat_smile: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 togetherAnyway, I'm giving up, and trying polysemy. Giving it an actual chance finally.
I think polysemy embraces Boring Haskell more than mtl (in a philosophical sense).