Uh oh!
There was an error while loading. Please reload this page.
add MonadThrow and MonadCatch instances for Stream - #121
Conversation
These are equivalent to the code in the existing MonadError instance.
treeowl
commented
Jul 4, 2023
Please leave a comment proving the |
Is the following correct/complete? I can prove the Lemma 1: throwM e >>= f = throwM eProof: throwM e >>= f =-- MonadThrow law (in reverse) for some arbitrary action 'w'-- (in particular, you can always choose w = throwM e)
(throwM e >> w) >>= f =-- my assumption
(throwM e >>=\_ -> w) >>= f =-- Monad associativity
throwM e >>= (\x -> (\_ -> w) x >>= f) =-- beta reduction
throwM e >>= (\_ -> w >>= f) =-- my assumption, again
throwM e >> (w >>= f)
-- MonadThrow law
throwM eLemma 2: fmap f (throwM e) = throwM eProof: fmap f (throwM e) =-- behavior of fmap for monads
throwM e >>=return. f
-- lemma 1
throwM eTheorem 1 (MonadThrow law for throwM e >> f = throwM eProof: throwM e >> f =-- definition of throwM, (>>) for Stream
lift (throwM e) *> f =-- definition of lift for StreamEffect (fmapReturn (throwM e)) *> f =-- lemma 2 for mEffect (throwM e) *> f =-- definition of (*>) for StreamEffect (fmap loop (throwM e)) =-- this 'loop' is a local function in (*>) and hides a reference to 'f'-- lemma 2 for mEffect (throwM e) =-- lemma 2 for mEffect (fmapReturn (throwM e)) =-- definition of lift for Stream
lift (throwM e) =-- definition of throwM for Stream
throwM eTheorem 2 (MonadCatch law for catch (throwM e) f = f eProof: catch (throwM e) f =-- definition of throwM for Stream
catch (lift (throwM e)) f =-- definition of lift for Stream
catch (Effect (fmapReturn (throwM e))) f =-- lemma 2 for m
catch (Effect (throwM e)) f =-- definition of catch for StreamEffect (fmap loop (throwM e) `catch` (return. f)) =-- lemma 2 for mEffect (throwM e `catch` (return. f)) =-- MonadCatch law for mEffect (return (f e))
-- definition of effect
effect (return (f e))
-- specification/law of effect
(join . lift) (return (f e))
-- associativity of (.)
join ((lift .return) (f e))
-- MonadTrans law
join (return (f e))
-- definition of joinreturn (f e) >>=id-- Monad lawid (f e)
-- definition of id
f e |
As for examples of desirable behavior, do you mean something like this? S.print (doS.yield "start"do { xs <- liftIO $fmaplines (readFile"some-imaginary-file");
S.each xs }
S.yield "finish"
)
{-"start"*** Exception: some-imaginary-file: openFile: does not exist (No such file or directory)-}S.print (doS.yield "start"do { xs <- liftIO $fmaplines (readFile"some-imaginary-file");
S.each xs }
`catchIOError` (\e ->do
liftIO $ hPutStrLn stderr $"caught an error: "++show e
S.yield "something else"
)
S.yield "finish"
)
{-"start"caught an error: some-imaginary-file: openFile: does not exist (No such file or directory)"something else""finish"-}What would "bad" behavior look like? |
mauke
commented
Jul 26, 2023
@treeowl Ping? |
treeowl
commented
Jul 26, 2023
Been sick for a week. Please ping again later. |
mauke
commented
Jul 26, 2023
Get well soon! |
mauke
commented
Oct 12, 2023
Ping? |
Topsii
commented
Nov 23, 2023
@treeowl ping |
No description provided.