Skip to content

Commit 00f5a2f

Browse files
committed
Fix incorrect implementation of foldFree
1 parent 3586dc4 commit 00f5a2f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/FreeX.hs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{-# LANGUAGE ExistentialQuantification #-}
22
{-# LANGUAGE UndecidableInstances, FlexibleInstances #-}
33
{-# LANGUAGE TypeOperators, TypeApplications, RankNTypes #-}
4+
{-# LANGUAGE AllowAmbiguousTypes #-}
45
{-# LANGUAGE DeriveFunctor #-}
56

67
module FreeX () where
@@ -70,9 +71,11 @@ concatFree (Free frfr) = Free (fmap concatFree frfr)
7071
liftFree :: Functor f => forall a. f a -> Free f a
7172
liftFree = Free . fmap Pure
7273

73-
foldFree :: Functor f => forall a. (f a -> a) -> Free f a -> a
74-
foldFree f (Pure a) = a
75-
foldFree f (Free ffra) = f $ fmap (foldFree f) ffra
74+
foldFree :: (Functor f, Applicative m, Monad m) => (forall x. (f x -> m x)) -> Free f a -> m a
75+
foldFree eta (Pure a) = pure a
76+
foldFree eta (Free ffra) = join (eta $ fmap (foldFree eta) ffra)
77+
-- foldFree eta (Free ffra) = join (fmap (foldFree eta) (eta ffra))
78+
-- foldFree eta (Free ffra) = eta ffra >>= foldFree eta
7679

7780
-- hoistFree
7881
freeMap :: (Functor f, Functor g) => (f :~> g) -> Free f a -> Free g a
@@ -335,6 +338,7 @@ type MemState = State [Int]
335338
type MemState' = State' [Int]
336339

337340
-- | This function is used for demostrate f = free f . ins
341+
-- The interp is just foldFree
338342
interp :: (Functor f, Monad m) => (f :~> m) -> (Free f :~> m)
339343
interp phi = monad . freeMap phi
340344

0 commit comments

Comments
 (0)