Skip to content

Commit 1faad9d

Browse files
authored
Merge pull request #94 from ajnsit/wrap
Add wrap
2 parents 4963e00 + 4c7d0ca commit 1faad9d

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/Control/Monad/Free.purs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module Control.Monad.Free
22
( Free
33
, suspendF
4+
, wrap
45
, liftF
56
, hoistFree
67
, foldFree
@@ -121,16 +122,20 @@ liftF f = fromView (Bind (unsafeCoerceF f) (pure <<< unsafeCoerceVal))
121122
unsafeCoerceVal :: forall a. Val -> a
122123
unsafeCoerceVal = unsafeCoerce
123124

124-
-- | Suspend a value given the applicative functor `f` into the free monad.
125-
suspendF :: forall f. Applicative f => Free f ~> Free f
126-
suspendF f = fromView (Bind (unsafeCoerceF (pure f)) unsafeCoerceVal)
125+
-- | Add a layer.
126+
wrap :: forall f a. f (Free f a) -> Free f a
127+
wrap f = fromView (Bind (unsafeCoerceF f) unsafeCoerceVal)
127128
where
128-
unsafeCoerceF :: forall a. f (Free f a) -> f Val
129+
unsafeCoerceF :: forall b. f (Free f b) -> f Val
129130
unsafeCoerceF = unsafeCoerce
130131

131-
unsafeCoerceVal :: forall a. Val -> Free f a
132+
unsafeCoerceVal :: forall b. Val -> Free f b
132133
unsafeCoerceVal = unsafeCoerce
133134

135+
-- | Suspend a value given the applicative functor `f` into the free monad.
136+
suspendF :: forall f. Applicative f => Free f ~> Free f
137+
suspendF f = wrap (pure f)
138+
134139
-- | Use a natural transformation to change the generating type constructor of a
135140
-- | free monad.
136141
hoistFree :: forall f g. (f ~> g) -> Free f ~> Free g

0 commit comments

Comments
 (0)