cobbpg / elerea

A simple FRP library providing leak-free first-class streams.
BSD 3-Clause "New" or "Revised" License
116 stars 8 forks source link

Add MonadIO instance for SignalGen #7

Closed maoe closed 9 years ago

maoe commented 9 years ago

Is there any reason why SignalGen isn't an instance of MonadIO? execute seems to satisfy the MonadIO laws:

1) execute . return = return

    execute . return
    = \x -> execute (return x)
    = \x -> SG (\_ -> return x)

    return
    = \x -> SG (\_ -> return x)

2) execute (m >>= f) = execute m >>= execute . f

    execute (m >>= f)
    = SG (\_ -> m >>= f)

    execute m >>= execute . f
    = SG (\_ -> m) >>= execute . f
    = SG (\p -> (\_ -> m) p >>= \x -> unSG (execute (f x)) p)
    = SG (\p -> m >>= \x -> unSG (execute (f x)) p)
    = SG (\p -> m >>= \x -> unSG (SG (\_ -> f x)) p)
    = SG (\p -> m >>= \x -> (\_ -> f x) p)
    = SG (\_ -> m >>= \x -> f x)
    = SG (\_ -> m >>= f)

I think the same applies to FRP.Elerea.Clocked and FRP.Elerea.Param.

cobbpg commented 9 years ago

As far as I remember, the reason was simply the desire to avoid dependency on mtl. Back when I originally implemented Elerea there was some confusion about which monad transformer library to use, so I figured anybody that wanted liftIO could do exactly what you did here. But I think this problem doesn’t exist any more.