Open safareli opened 7 years ago
@jdegoes I would love to hear your thoughts on this.
@safareli if you haven't seen it already, there's some discussion of concurrent free applicatives in section 5.4 of "There is no fork" http://dl.acm.org/citation.cfm?id=2628144
If Free is no longer a (concurrent) Applicative, it wouldn't be possible to use generic functions like lift
with it, which would be a bit of a shame.
url is not working
(amended the link - from there, follow the link to the pdf)
If Free is no longer a (concurrent) Applicative, it wouldn't be possible to use generic functions like
lift
with it, which would be a bit of a shame.
Free is concurrent if target monad is not lawful. so if in perfect world all Task/Futures are lawful then there will be no concurrency benefits from dispatching to ap
of target monad.
if we add some minimal concurrency constructs to Free and then it would be possible to still fold it concurrently when target monad is lawful.
related issue: fantasy-land#179
will take a look at that paper but haxl is not lawful as well
I like it. FWIW, or
is often called race
, and and
is equivalent to a function normally called par
. See purescript-parallel
, for example.
MonadPar
and MonadRace
from purescript-parallel
are what we need in JS will create an issue FL for that, thanks!
If we had that algebras in FL then foldMap would become:
foldMap :: (ChainRace m, ChainRec m, Monad m) => Free i a ~> (i -> m a) -> TypeRep m -> m a
And with something like Parallel we can transform (Monad m, ChainRace m)
into just Applicative
which is concurant (i.e. we would be able to use lift and general functions over Applicative
while still be concurant)
Also related: SeqPar - Free applicative in free monad
Currently i'm porting the recent version of haskell-free-concurrent. Before I did not understood the implementation because of Lenses and it's strange operators, but now I did another try and i got it 🎉
I was thinking what if instead of ignoring law
<*> = ap
make Free lawfull but add two methodsor
andand
which could be used when actions should be resolved concurrently.possibly change
foldmap
to somethink like this:we would need to change type of Free to:
it would also change description of the repo
With this constructs we could also have this static methods on Free: