purescript-contrib / purescript-fork

An MTL-style class for monads that support forking
Apache License 2.0
8 stars 6 forks source link

Make lawful #2

Closed jdegoes closed 7 years ago

jdegoes commented 7 years ago

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)
natefaubion commented 7 years ago

That was kind of the idea with the original formulation that had cancelWith as a member (cancelWith is just difficult to implement in general). The problem with cancellation is that your effects may have already run (in fact if its all synchronous effects, it definitely has already run), and so while you can say they are algebraically equivalent, they are a far cry from being observably equivalent. For example, with this law, it suggestively implies that cancelling immediately after forking an effect is observably equivalent to throwing before running the effect, which is not possible in any forking environment (JS engines or otherwise).