question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add spec for Pearing of Monad and Applicative

See original GitHub issue

in purescript-parallel there are this classes:

-- | The `MonadPar` class abstracts over monads which support some notion of
-- | parallel composition.
-- |
-- | The `unit` and `par` functions should correspond to `pure` and `lift2` for
-- | some valid `Applicative` instance, but that instance need not arise from
-- | the underlying `Monad`.
class Monad m <= MonadPar m where
  par :: forall a b c. (a -> b -> c) -> m a -> m b -> m c

-- | The `MonadRace` class extends `MonadPar` to those monads which can be
-- | _raced_. That is, monads for which two computations can be executed in parallel
-- | returning the result from the computation which finishes first.
-- |
-- | The `stall` and `race` functions should satisfy the `Alternative` laws.
class MonadPar m <= MonadRace m where
  stall :: forall a. m a
  race :: forall a. m a -> m a -> m a

I think we should add them to fantasy land spec so that different implementations of Future/Task could implement them consistently such that libs like @safareli/Free and @DrBoolean/freeky could depend on them.

If we had this algebras we can also port Parallel using which we can transform any (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) which is awasome!

I think we should name use this names as they dont need structure to be a monad:

  • ChainPar for MonadPar
  • ChainRace for MonadRace

realted issues:

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
safarelicommented, Oct 26, 2016

After reading this reddit thread i’m thinking that name Parallel or Concurent is not that precise as this spec shuold just pearing/isomorphism between some Monad and some Applicative.

This are example are not strictly related to concurrency/parallelism:

  • List Monad and ZipList Applicative
  • Either Monad and Validation Applicative

for now i don’t have a better name but will think on this.

0reactions
safarelicommented, Nov 21, 2016

This will be useful in Free monad like structures. for example one might have Free&FreeAp conforming to this spec user could switch from one to another when it’s appropriate, and then it could be folded down to some other Monad&Applicative pear Task/Future …

Or one might for example in one computation use Either then convert it to Validation and then back to Either (when error is monoid), but I see most use with Task/Future.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Your easy guide to Monads, Applicatives, & Functors - Medium
The pure and first apply call wrapped three partially applied add s inside a list but you can substitute the pure and one...
Read more >
Typeclassopedia - HaskellWiki
Here is the type class declaration for Applicative , as defined in ... Haskell does, in fact, single out monads for special attention...
Read more >
The Monad Understanding Hurdle - YouTube
Monads are a design pattern in programming linked to category theory in the early 90s. They have been a fundamental part, that is, ......
Read more >
The Remote Monad Design Pattern
ple, if we add a monadic command that returns a Boolean, ... In §6 we build a remote applicative functor, which exploits the...
Read more >
Difference between Monad and Applicative in Haskell
Now the implementation of (<*>) is the special part worth considering carefully. ... Now, if we add in the Constant functor/applicative:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found