|
1 | 1 | {-# LANGUAGE ExistentialQuantification #-}
|
2 | 2 | {-# LANGUAGE UndecidableInstances, FlexibleInstances #-}
|
3 | 3 | {-# LANGUAGE TypeOperators, TypeApplications, RankNTypes #-}
|
| 4 | +{-# LANGUAGE AllowAmbiguousTypes #-} |
4 | 5 | {-# LANGUAGE DeriveFunctor #-}
|
5 | 6 |
|
6 | 7 | module FreeX () where
|
@@ -70,9 +71,11 @@ concatFree (Free frfr) = Free (fmap concatFree frfr)
|
70 | 71 | liftFree :: Functor f => forall a. f a -> Free f a
|
71 | 72 | liftFree = Free . fmap Pure
|
72 | 73 |
|
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 |
76 | 79 |
|
77 | 80 | -- hoistFree
|
78 | 81 | freeMap :: (Functor f, Functor g) => (f :~> g) -> Free f a -> Free g a
|
@@ -335,6 +338,7 @@ type MemState = State [Int]
|
335 | 338 | type MemState' = State' [Int]
|
336 | 339 |
|
337 | 340 | -- | This function is used for demostrate f = free f . ins
|
| 341 | +-- The interp is just foldFree |
338 | 342 | interp :: (Functor f, Monad m) => (f :~> m) -> (Free f :~> m)
|
339 | 343 | interp phi = monad . freeMap phi
|
340 | 344 |
|
|
0 commit comments