-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider a backpack-based implementation? #317
Comments
Oh, and another reason to prefer backpack: it cleans up type signatures a lot :) Compare: -- typeclass
newScope :: MonadConc m => m (TMVar (STM m) (Scope m))
-- backpack
newScope :: IO (TMVar Scope) |
This is something I've been interested in for a while (added to my to-do list in October 2018!) but I've just never got around to trying it out. Is there a good primer on backpack somewhere?
Yeah, keeping that feature would be good. It was originally added for a user who does some complex (but deterministic) set-up work at the start of their tests, and dejafu was spending way too much time working through that. Previously I solved that problem with two functions, I wonder if changing the representation a bit would cause any insurmountable problems:
Or maybe they could be three separate types, and the functions in Test.DejaFu which consume a |
Another thought: what about keeping Then for the |
I don't there's a great, concise primer. I found this wiki page which contains all the info you need, scattered about :) https://gitlab.haskell.org/ghc/ghc/-/wikis/backpack I also had a peep at this cabal file when I ran into some trouble.
Oh yeah, totally! It's only the version of the program that runs in IO that you want to code against a signature. The tests could (obviously) just use Edit: whoops, got a little confused for a second. I think you'd actually have trouble writing an implementation of the signature with polymorphic functions. Not sure how that would look 🤔 |
Hi, have you considered a backpack-based implementation of
concurrency
/dejafu
? I think it'd be preferable to the typclass-based version (if it makes sense to do so).One reason: even assuming specialization of all functions, some operations are just more efficient with
base
. For example,concurrency
doesn't have access to the timer manager, so its implementation of registerDelay forks a thread.I started down a path of writing a little concurrency library that internally was generic in
MonadConc m
, with functions exposed in an internal module for testing. The interface was specialized to IO in the user-facing part of the library.But once I realized
registerDelay
forked a thread, I switched to using a signature instead, with just the bits I usedhttps://github.com/mitchellwrosen/trio/blob/d82595b643a39ad4678e4ae2c3bd6304f20cc06f/src/trio-indef/Trio/Sig.hsig
with two implementations, base and dejafu:
https://github.com/mitchellwrosen/trio/blob/d82595b643a39ad4678e4ae2c3bd6304f20cc06f/src/trio-impl-base/Trio/Sig/Base.hs
https://github.com/mitchellwrosen/trio/blob/d82595b643a39ad4678e4ae2c3bd6304f20cc06f/src/trio-impl-dejafu/Trio/Sig/Dejafu.hs
The wrapping was all pretty easy, and boilerplatey. It'd be nice to centralize its implementation somewhere :)
One thing I'm not sure of is the type-changing
Program
, depending on if you have setup or teardown. My test suite doesn't, so I didn't have to deal with that complication.The text was updated successfully, but these errors were encountered: