Replies: 1 comment 9 replies
-
For the record, I already expressed on reddit and discourse why I think passing effects explicitly is much less ergonomic than having them as constraints. However, I realize that there might be a need of having multiple instances of a specific effect in scope at the same time. So I experimented a bit and came up with #138. Let me know what you think about this. |
Beta Was this translation helpful? Give feedback.
9 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a general question and I'm not sure it has an answer, but I thought it would be interesting to get a discussion going.
We generally have two options when we want to work with effects:
effectful
, this means defining an effect. Here the effect is threaded implicitly/automatically by GHC through type class constraints.For example, if I want to connect to a database I can either define an effect that gives me access to a database (e.g.,
Effectful.HPQTypes
), or I can just thread around a handle to that connection (e.g., apostgresql-simple
Connection
).Now this comparison might not be fair, because you might say that
hpqtypes-effectful
allows for re-interpretation of the effect. That's true, but we can also get that with the handle approach - we simply make our handle a record of effects.The handle approach scales well when it comes to needing multiple instances of something. Having a single database connection requires the same type of code as multiple. However, in an effectful context dispatching queries to particular connections becomes much harder.
It can be sometimes hard to know when you'll only have a single instance or multiple, and in that sense the handle approach is quite nice and uniform.
To put this discussion in context, I'm exploring using
effectful
for a project at work. In this project I currently use the handle pattern, and I'm wondering whether or not I want to change that. I have some physical machinery that I can talk to to actuate motors or trigger cameras. The cameras in particular are problematic as we have multiple. The design I'm probably going to explore is having handles to various bits of machinery, but the actual acquisition or use of that handle requires access to aHardware
effect. In the database world, this would mean changinghpqtypes-effectful
to be a combination of both a handle and an effect that lets you use the handle:This is a bit rambly, and I don't quite know how to put into words what my actual question is - but I thought I'd just try and get some thoughts out! CC @tomjaguarpaw, as I know you're very interested in a more explicit encoding of effect handles.
Beta Was this translation helpful? Give feedback.
All reactions