Skip to content

Commit 6868fb7

Browse files
committed
More general resume
1 parent 346fd8e commit 6868fb7

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/Control/Monad/Free.purs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module Control.Monad.Free
88
, runFree
99
, runFreeM
1010
, resume
11+
, resume'
1112
) where
1213

1314
import Prelude
@@ -188,9 +189,18 @@ resume
188189
. Functor f
189190
=> Free f a
190191
-> Either (f (Free f a)) a
191-
resume f = case toView f of
192-
Return a -> Right a
193-
Bind g i -> Left (i <$> g)
192+
resume = resume' (\g i -> Left (i <$> g)) Right
193+
194+
-- | Unwraps a single layer of `f`, providing the continuation.
195+
resume'
196+
:: forall f a r
197+
. (forall b. f b -> (b -> Free f a) -> r)
198+
-> (a -> r)
199+
-> Free f a
200+
-> r
201+
resume' k j f = case toView f of
202+
Return a -> j a
203+
Bind g i -> k g i
194204

195205
fromView :: forall f a. FreeView f a Val -> Free f a
196206
fromView f = Free (unsafeCoerceFreeView f) empty

0 commit comments

Comments
 (0)