purescript-lazy icon indicating copy to clipboard operation
purescript-lazy copied to clipboard

Lazy IO

Open paf31 opened this issue 9 years ago • 5 comments

We could provide unsafeLazyEff :: forall eff a. Eff eff a -> Eff eff (Lazy a) which will allow us to support lazy IO.

For example, random numbers can be generated as lazy infinite lists. Right now this is a bit of a pain.

Note this is not a substitute for things like chunked IO via Aff where we want to receive data asynchronously, but it might still be useful for synchronous effects.

paf31 avatar Jun 21 '16 16:06 paf31

Do we want this in purescript-lazy or in purescript-eff? I think the latter is a bigger package.

no-longer-on-githu-b avatar Apr 08 '17 12:04 no-longer-on-githu-b

I think the implementation could just be this, right?

unsafeLazyEff :: forall eff a. Eff eff a -> Eff eff (Lazy a)
unsafeLazyEff a = pure $ defer \_ -> unsafePerformEff a

no-longer-on-githu-b avatar Apr 08 '17 12:04 no-longer-on-githu-b

Is this the only way to support lazy IO? Is there anything stopping one from creating a monad implementing MonadEff that allows for a deferred bind?

(I ask because of the wording "which will allow us to support lazy IO." I recognize that even if the above is a possible/preferred approach, "cheating" can be very handy.)

matthewleon avatar Apr 13 '17 09:04 matthewleon

I think that implementation is good, assuming we want to support lazy IO at all. It can be handy for modularity in certain cases, although obviously you need to be careful.

paf31 avatar Apr 13 '17 16:04 paf31

I think this needs further discussion on whether we would want to do this and then where to put it.

JordanMartinez avatar Dec 04 '21 16:12 JordanMartinez