Giter VIP home page Giter VIP logo

purescript-fork's Introduction

Fork

CI Release Pursuit Maintainer: garyb

Monads which support a forking operation.

Installation

Install fork with Spago:

spago install fork

Quick start

The quick start hasn't been written yet (contributions are welcome!). The quick start covers a common, minimal use case for the library, whereas longer examples and tutorials are kept in the docs directory.

Documentation

fork documentation is stored in a few places:

  1. Module documentation is published on Pursuit.
  2. Written documentation is kept in the docs directory.
  3. Usage examples can be found in the test suite.

If you get stuck, there are several ways to get help:

Contributing

You can contribute to fork in several ways:

  1. If you encounter a problem or have a question, please open an issue. We'll do our best to work with you to resolve or answer it.

  2. If you would like to contribute code, tests, or documentation, please read the contributor guide. It's a short, helpful introduction to contributing to this library, including development instructions.

  3. If you have written a library, tutorial, guide, or other resource based on this package, please share it on the PureScript Discourse! Writing libraries and learning resources are a great way to help this library succeed.

purescript-fork's People

Contributors

artemissystem avatar garyb avatar jordanmartinez avatar justinwoo avatar kl0tl avatar kritzcreek avatar natefaubion avatar th-awake avatar thomashoneyman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

purescript-fork's Issues

Instanes for ExceptT?

I tried to implement some of this classes with ExceptT

MonadFork with Compose (Aff.Fiber eff) (Either MyError) as fiber could be implemented just fine

data MyError = MyCustomError

newtype M eff a = M (ExceptT MyError (Aff.Aff eff) a)

runM :: forall eff a. M eff a -> Aff.Aff eff (Either MyError a)
runM (M (ExceptT x)) = x

derive newtype instance functorM :: Functor (M e)
derive newtype instance applyM :: Apply (M e)
derive newtype instance applicativeM :: Applicative (M e)
derive newtype instance bindM :: Bind (M e)
derive newtype instance monadM :: Monad (M e)
derive newtype instance monadEffM :: MonadEff e (M e)
derive newtype instance monadAffMMonadAff e (M e)

instance monadForkMMonadFork (Compose (Aff.Fiber eff) (Either MyError)) (M eff) where
  suspend x = map Compose $ liftAff $ suspend $ runM x
  fork x = map Compose $ liftAff $ fork $ runM x
  join (Compose f) = M $ ExceptT $ join f

for MonadKill you need MonadThrow, i tried to implement it with Either MyError Aff.Error as error type, but i still have to do kill (Aff.error "kill") as in that case there is no Error around:

instance monadThrowM :: MonadThrow (Either MyError Aff.Error) (M e) where
  throwError (Left e) = M $ ExceptT $ pure $ Left e
  throwError (Right e) = M $ ExceptT $ throwError e

instance monadKillMMonadKill (Either MyError Aff.Error) (Compose (Aff.Fiber eff) (Either MyError)) (M eff) where
  kill (Left e) (Compose f) = M $ ExceptT $ kill (Aff.error "kill") f $> Left e
  kill (Right e) (Compose f) = M $ ExceptT $ map Right $ kill e f

for MonadBracket we need MonadError:

instance monadErrorM :: MonadError (Either MyError Aff.Error) (M e) where
  catchError x f = do
    res <- M $ ExceptT $ map Right $ Aff.try (runM x)
    case res of
      Left e -> f $ Right e
      Right (Left e) -> f $ Left e
      Right (Right a) -> pure a

But I got stack with bracket function of MonadBracket (uninterruptible and never are trivial to implement).

is it possible to implement correct bracket instance for ExceptT at all?

What should you do if you want some error type in your monad other then Error, is there some way which makes it possible to implement MonadBracket but still have custom error type?

Concurrency hierarchy

class (Monad m, Functor t) <= MonadFork t m | m -> t where
  fork :: forall a. m a -> m (t a)
  join :: forall a. t a -> m a

class (MonadFork t m, MonadThrow e m) <= MonadKill e t m | m -> e t where
  kill :: forall a. e -> t a -> m Unit

class (MonadKill e t m, MonadError e m) <= MonadBracket e t m | m -> e t where
  bracket :: forall a b. m a -> (a -> m Unit) -> (a -> m b) -> m b

MonadFork has a fairly obvious law of fork >=> join = id, but I'm not sure what I'd state about the others.

Make lawful

I'm not sure this is easy, but there's some intention here that may be able to be expressed as a law with a slightly richer Monad.

Not this, but along these lines:

(do 
 canceler <- fork effect
 canceler cause)
==
(do
  _ <- throw cause
  effect)

Unlawful Aff Instance?

Maybe I'm reading it wrong but the Aff instance for MonadKill seems to be incorrect.

suspend a >>= \f -> kill e f *> join f = throwError e

This is not the case for Aff. Joining on a killed fork is a panic. throwError uses the error channel, not the interrupt channel.

Needs a quick start section in the README

Is your change request related to a problem? Please describe.
As described in the documentation section of the Library Guidelines, Contributors libraries are expected to have in their README a short summary of the library's purpose, installation instructions, a quick start with a minimal usage example, and links to the documentation and contributing guide.

This library currently doesn't have a completed quick start in the README.

Describe the solution you'd like
The library needs a quick start section after the installation instructions. machines is a good example of a small, to-the-point quick start.

We could at least demonstrate a minimal example which uses suspend, fork, join, and kill.

Additional context
See the Governance repository for more information about requirements in the Contributors organization.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.