!Jf$@Z      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~                                  ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o pqrstuvwxyz{|}~      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXY(C) 2012 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> provisionalGADTs, Rank2TypesSafe&'2SX%free A version of lift that can be used with any f.free$Given a natural transformation from f to g>, this gives a canonical monoidal natural transformation from  f to g.free$Given a natural transformation from f to g3 this gives a monoidal natural transformation from Alt f to Alt g.  3(C) 2012 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> provisionalGADTs, Rank2TypesSafeSX-9free The free Z for any f.free A version of lift that can be used with f.free$Given a natural transformation from f to g>, this gives a canonical monoidal natural transformation from  f to g.free$Given a natural transformation from f to g3 this gives a monoidal natural transformation from Alt f to Alt g.(C) 2012-2013 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> provisionalGADTs, Rank2TypesSafe&'2SX:free The free [ for a \ f."free$Given a natural transformation from f to g>, this gives a canonical monoidal natural transformation from  f to g."runAp t == retractApp . hoistApp t#free8Perform a monoidal analysis over free applicative value.Example: =count :: Ap f a -> Int count = getSum . runAp_ (\_ -> Sum 1) $free A version of lift that can be used with just a \ for f.%freeTear down a free [ using iteration.&free$Given a natural transformation from f to g3 this gives a monoidal natural transformation from Ap f to Ap g.'freeJInterprets the free applicative functor over f using the semantics for ] and ^) given by the Applicative instance for f.retractApp == runAp id ! "#$%&' ! "#$%&'Safe&'2SXTy ,freeThe faster free [./freeThe free applicative is composed of a sequence of effects, and a pure function to apply that sequence to. The fast free applicative separates these from each other, so that the sequence may be built up independently, and so that _J can run in constant time by having immediate access to the pure function.2free>Interprets the sequence of effects using the semantics for ] and ^' given by the Applicative instance for f.3free$Given a natural transformation from f to g* this gives a natural transformation from ASeq f to ASeq g.4free=Traverse a sequence with resepect to its interpretation type f.5free It may not be obvious, but this essentially acts like ++, traversing the first sequence and creating a new one by appending the second sequence. The difference is that this also has to modify the return functions and that the return type depends on the input types.See the source of 9 as an example usage.6free$Given a natural transformation from f to g>, this gives a canonical monoidal natural transformation from , f to g."runAp t == retractApp . hoistApp t7free8Perform a monoidal analysis over free applicative value.Example: =count :: Ap f a -> Int count = getSum . runAp_ (\_ -> Sum 1) 8free A version of lift that can be used with just a \ for f.9free$Given a natural transformation from f to g3 this gives a monoidal natural transformation from Ap f to Ap g.:freeJInterprets the free applicative functor over f using the semantics for ] and ^) given by the Applicative instance for f.retractApp == runAp id,-./0123456789:/012345,-.8:679(C) 2012-2013 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> provisionalGADTs, Rank2TypesSafeSXa>free The free [ for a \ f.Afree$Given a natural transformation from f to g>, this gives a canonical monoidal natural transformation from > f to g."runAp t == retractApp . hoistApp tBfree8Perform a monoidal analysis over free applicative value.Example: =count :: Ap f a -> Int count = getSum . runAp_ (\_ -> Sum 1) Cfree A version of lift that can be used with just a \ for f.Dfree$Given a natural transformation from f to g3 this gives a monoidal natural transformation from Ap f to Ap g.EfreeJInterprets the free applicative functor over f using the semantics for ] and ^) given by the Applicative instance for f.retractApp == runAp id>?@ABCDE>?@ABCDE(C) 2012-2013 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> provisionalGADTs, Rank2TypesSafe&'2SX}Ifree The free Z for a \ f.Jfree The free [ for a \ f.Kfree The free [ transformer for a \ f over [ g.Nfree The free [ for a \ f.Qfree A version of lift) that can be used with no constraint for f.RfreeLift an action of the "outer" \ g a to K f g a.SfreeGiven natural transformations f ~> h and  g . h ~> h& this gives a natural transformation  ApF f g ~> h.TfreeGiven natural transformations f ~> h and  g . h ~> h& this gives a natural transformation  ApT f g ~> h.Ufree!Perform a monoidal analysis over K f g b value. Examples:  height :: (\ g, ` g) => K f g a -> a height = getSum . runApT_ (_ -> Sum 1) b  size :: (\ g, ` g) => K f g a -> a size = getSum . runApT_ (_ -> Sum 1) c Vfree$Given a natural transformation from f to f'3 this gives a monoidal natural transformation from ApF f g to ApF f' g.Wfree$Given a natural transformation from f to f'3 this gives a monoidal natural transformation from ApT f g to ApT f' g.Xfree$Given a natural transformation from g to g'3 this gives a monoidal natural transformation from ApF f g to ApF f g'.Yfree$Given a natural transformation from g to g'3 this gives a monoidal natural transformation from ApT f g to ApT f g'.ZfreePull out and join m layers of K f m a.[free$Given a natural transformation from f to g>, this gives a canonical monoidal natural transformation from N f to g."runAp t == retractApp . hoistApp t\free8Perform a monoidal analysis over free applicative value.Example:  count :: N f a -> a count = getSum . runAp_ (\_ -> Sum 1) ]freeJInterprets the free applicative functor over f using the semantics for ] and ^) given by the Applicative instance for f.retractApp == runAp id^free$Given a natural transformation from f to g>, this gives a canonical monoidal natural transformation from I f to g.IJKLMNPOQRSTUVWXYZ[\]^KLMNPOQRTSUWVYXZJ[\]I^(C) 2008-2011 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> experimentalfundeps, MPTCsSafe=?@ACffree0Allows you to peel a layer off a cofree comonad.gfreeRemove a layer.fgfg(C) 2008-2013 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> provisionalMPTCs, fundepsSafe 27=?@ASX5 ofree The cofree d of a functor f.pfree)This is a cofree comonad of some functor f, with a comonad w# threaded through it at each level.sfree;This is the base functor of the cofree comonad transformer.ufree$Extract the head of the base functorvfree%Extract the tails of the base functorwfree1Wrap another layer around a cofree comonad value.cofree is a right inverse of x. runCofree . cofree == id xfree2Unpeel the first layer off a cofree comonad value. runCofree is a right inverse of w. cofree . runCofree == id yfree#Lift a natural transformation from f to g" into a comonad homomorphism from p f w to p g wzfree Unfold a CofreeT= comonad transformer from a coalgebra and an initial comonad.fgopqrstuvwxyzpqrowxstfguvyzt5 (C) 2008-2015 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> experimentalnon-portable (fundeps, MPTCs)Safe 8=?@ACHV)freeMonads provide substitution (_) and renormalization (e): m f f = e (_ f m)A free go is one that does no work during the normalization step beyond simply grafting the two monadic values together.[] is not a free g (in this sense) because e [[a]] smashes the lists flat.On the other hand, consider: ,data Tree a = Bin (Tree a) (Tree a) | Tip a   instance g Tree where h = Tip Tip a f f = f a Bin l r f f = Bin (l f f) (r f f) This g is the free g of Pair: data Pair a = Pair a a !And we could make an instance of  for it directly:  instance  Pair Tree where  (Pair l r) = Bin l r #Or we could choose to program with  Pair instead of Tree- and thereby avoid having to define our own g instance. Moreover, Control.Monad.Free.Church provides a  instance that can improve the  asymptotic[ complexity of code that constructs free monads by effectively reassociating the use of (f+). You may also want to take a look at the kan-extensions package ( 1http://hackage.haskell.org/package/kan-extensions).See * for a more formal definition of the free g for a \.free Add a layer. -wrap (fmap f x) "a wrap (fmap return x) >>= f free=A version of lift that can be used with just a Functor for f.free;A version of wrap for monad transformers over a free monad.Note:- that this is the default implementation for  for MonadFree f (t m). (C) 2008-2013 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> provisionalMPTCs, fundepsSafe ifreerPick a name for an operation. For normal constructors it lowers first letter. For infix ones it omits the first :.jfree#Check if parameter is used in type.kfreeAnalyze constructor argument.lfreeTApply transformation to the return value independently of how many parameters does e have. E.g.  mapRet Just (x y z -> x + y * z) goes to x y z -> Just (x + y * z)mfreeUnification of two types. next with  a -> next gives Maybe a return type  a -> next with  b -> next gives  Either a b return typenfreeyUnifying a list of types (possibly refining expressions). Name is used when the return type is supposed to be arbitrary.ofree<Provide free monadic actions for a single value constructor.pfreeGet construstor name(s).qfree4Provide free monadic actions for a type declaration.rfree)Generate monadic actions for a data type.sfree@Generate monadic action for a single constructor of a data type.free$( ''T)L provides free monadic actions for the constructors of the given data type T.freeLike , but does not provide type signatures. This can be used to attach Haddock comments to individual arguments for each generated function. data LangF x = Output String x makeFree_ 'LangF -- | Output a string. output :: MonadFree LangF m => String -- ^ String to output. -> m () -- ^ No result. 6 must be called *before* the explicit type signatures.free$( 'Con)6 provides free monadic action for a data constructor Conx. Note that you can attach Haddock comment to the generated function by placing it before the top-level invocation of : *-- | Output a string. makeFreeCon 'Output freeLike n, but does not provide a type signature. This can be used to attach Haddock comments to individual arguments. data LangF x = Output String x makeFreeCon_ 'Output -- | Output a string. output :: MonadFree LangF m => String -- ^ String to output. -> m () -- ^ No result. 5 must be called *before* the explicit type signature.qfreeInclude type signature?freeDInclude only mentioned constructor names. Use all constructors when Nothing.freeData type declaration.rfreeInclude type signature?freeDInclude only mentioned constructor names. Use all constructors when Nothing.free Type name.freeGenerated declarations.sfreeInclude type signature?freeConstructor name.freeGenerated declarations.Safeg5tuvwxyz{|}~ (C) 2013 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> provisionalMPTCs, fundepsSafe 2=?@ASXfreePlain iterative computations.free7The monad supporting iteration based over a base monad m.  ~ FreeT  free4Builds an iterative computation from one first step.runIter . iter == idfree3Executes the first step of an iterative computationiter . runIter == idfree*Adds an extra layer to a free monad value.'In particular, for the iterative monad X, this makes the computation require one more step, without changing its final result.runIter (delay ma) == Right mafree is the left inverse of   .  =  free Tear down a Free g using iteration.freeLike  with monadic result.freeLift a monad homomorphism from m to n into a Monad homomorphism from  m to  n.freeGLifts a plain, non-terminating computation into a richer environment.  is a g homomorphism.free#A computation that never terminatesfree1Repeatedly run a computation until it produces a K value. This can be useful when paired with a monad that has side effects.For example, we may have genId :: IO (Maybe Id)z that uses a random number generator to allocate ids, but fails if it finds a collision. We can repeatedly run this with  ( genId) :: IO Id freeCuts off an iterative computation after a given number of steps. If the number of steps is 0 or less, no computation nor monadic effects will take place.IThe step where the final value is produced also counts towards the limit.Some examples (n "e 0):  0 _ "a h   (n+1)  h "a h    (n+1)   "a      (n+1)   "a  .  n  n  "a   (h )  n Calling    nT is always terminating, provided each of the steps in the iteration is terminating.free`Interleaves the steps of a finite list of iterative computations, and collects their results.VThe resulting computation has as many steps as the longest computation in the list.freeVInterleaves the steps of a finite list of computations, and discards their results.VThe resulting computation has as many steps as the longest computation in the list.Equivalent to void  .free Capretta's race" combinator. Satisfies left catch. Safe 127=?@ASX>free$The "free monad" for an applicative f.free0The "free monad transformer" for an applicative ffree"The base functor for a free monad.free4Evaluates the first layer out of a free monad value.free'Pushes a layer into a free monad value.free'Given an applicative homomorphism from f (m a) to m a6, tear down a free monad transformer using iteration.free'Given an applicative homomorphism from  f (t m a) to t m aI, tear down a free monad transformer using iteration over a transformer.freeLift a monad homomorphism from m to n into a monad homomorphism from  f m to  f n  :: (g m, \ f) => (m ~> n) ->  f m ~>  f nfree&Lift an applicative homomorphism from f to g into a monad homomorphism from  f m to  g mfreePull out and join m layers of  f m a.free is the left inverse of   .  =  free'Given an applicative homomorphism from f to , tear down a  g using iteration.freeLike  for monadic values.freeCCuts off a tree of computations at a given depth. If the depth is 0> or less, no computation nor monadic effects will take place.Some examples (n "e 0):  0 _ "a h   (n+1)  h "a h    (n+1)   "a      (n+1)   "a   _ ( n) Calling    nT is always terminating, provided each of the steps in the iteration is terminating.freepartialIterT n phi m interprets first n layers of m using phi$. This is sort of the opposite for .Some examples (n "e 0):  0 _ m "a m  (n+1) phi  h "a h  (n+1) phi   "a   (n+1) phi   "a e .  . phi freeintersperseT f m inserts a layer f between every two layers in m.  f  h "a h  f   "a   f   "a   _ ( (  ( f)  )) free<Tear down a free monad transformer using Monad instance for t m.freeintercalateT f m inserts a layer f between every two layers in m and then retracts the result.  f "a  .  f  (C) 2008-2013 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> provisionalMPTCs, fundepsSafe 127=?@ASX:(freeThe "free monad" for a functor f.)free+The "free monad transformer" for a functor f,free"The base functor for a free monad./free4Evaluates the first layer out of a free monad value.0free'Pushes a layer into a free monad value.1free3Tear down a free monad transformer using iteration.2freeFTear down a free monad transformer using iteration over a transformer.3freeLift a monad homomorphism from m to n into a monad homomorphism from ) f m to ) f n 3 :: (g m, \ f) => (m ~> n) -> ) f m ~> ) f n4freeThe very definition of a free monad transformer is that given a natural transformation you get a monad transformer homomorphism.5free#Lift a natural transformation from f to g into a monad homomorphism from ) f m to ) g m6freePull out and join m layers of ) f m a.7free7 is the left inverse of  7 .  =  8free Tear down a , g using iteration.9freeLike 8 for monadic values.:freeCCuts off a tree of computations at a given depth. If the depth is 0> or less, no computation nor monadic effects will take place.Some examples (n "e 0): : 0 _ "a h  : (n+1)  h "a h   : (n+1)   "a     : (n+1)   "a   _ (: n) Calling 7  : nT is always terminating, provided each of the steps in the iteration is terminating.;freepartialIterT n phi m interprets first n layers of m using phi$. This is sort of the opposite for :.Some examples (n "e 0): ; 0 _ m "a m ; (n+1) phi  h "a h ; (n+1) phi   "a  ; (n+1) phi   "a e .  . phi <freeintersperseT f m inserts a layer f between every two layers in m. < f  h "a h < f   "a  < f   "a   _ (2 (  ( f)  )) =free<Tear down a free monad transformer using Monad instance for t m.>freeintercalateT f m inserts a layer f between every two layers in m and then retracts the result. > f "a = . < f ()*+,-./0123456789:;<=>,-.)*+(0/123456:;<>=789(C) 2008-2014 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> provisional)non-portable (rank-2 polymorphism, MTPCs)Safe=?@ASX`5pfreeThe "free monad" for a functor f.qfree+The "free monad transformer" for a functor ftfree8Generate a Church-encoded free monad transformer from a ) monad transformer.ufree Convert to a ) free monad representation.vfree Unwrap the ,4 monad to obtain it's Church-encoded representation.wfreeIWrap a Church-encoding of a "free monad" as the free monad for a functor.xfree3Tear down a free monad transformer using iteration.yfreeFTear down a free monad transformer using iteration over a transformer.zfreeLift a monad homomorphism from m to n into a monad homomorphism from q f m to q f n z :: (g m, g n, \ f) => (m ~> n) -> q f m ~> q f n{free#Lift a natural transformation from f to g into a monad homomorphism from q f m to q g n|freePull out and join m layers of ) f m a.}freeCuts off a tree of computations at a given depth. If the depth is 0 or less, no computation nor monadic effects will take place.Some examples (n "e 0):'cutoff 0 _ == return Nothing&cutoff (n+1) . return == return . Just,cutoff (n+1) . lift == lift . liftM Just0cutoff (n+1) . wrap == wrap . fmap (cutoff n)pCalling 'retract . cutoff n' is always terminating, provided each of the steps in the iteration is terminating.~free~ is the left inverse of  ~ .  =  freeFTear down a free monad transformer using iteration over a transformer.free Tear down an p g using iteration.freeLike  for monadic values.free-Convert to another free monad representation.free,Generate a Church-encoded free monad from a , monad.freeiImprove the asymptotic performance of code that builds a free monad with only binds and returns by using p behind the scenes.OThis is based on the "Free Monads for Less" series of articles by Edward Kmett: 4http://comonad.com/reader/2011/free-monads-for-less/ 6http://comonad.com/reader/2011/free-monads-for-less-2/Tand "Asymptotic Improvement of Computations over Free Monads" by Janis Voightlnder: (http://www.iai.uni-bonn.de/~jv/mpc08.pdffreevImprove the asymptotic performance of code that builds a free monad transformer with only binds and returns by using q behind the scenes. Similar to .pqrstuvwxyz{|}~qrspwvtuxyz{|}~Safe 27=?@ASX{?free!A free monad given an applicativefree is the left inverse of  and   .  =   .  =  free'Given an applicative homomorphism from f to Identity, tear down a  g using iteration.freeLike  for applicative values.freeLike  for monadic values.free&Lift an applicative homomorphism from f to g into a monad homomorphism from  f to  g.free@Given an applicative homomorphism, you get a monad homomorphism.free Convert a  monad from Control.Monad.Free.Ap to a  monad from Control.Monad.Trans.Free.Ap. WARNING: This assumes that  is an applicative homomorphism.freeCuts off a tree of computations at a given depth. If the depth is 0 or less, no computation nor monadic effects will take place.Some examples (n "e 0):'cutoff 0 _ == return Nothing&cutoff (n+1) . return == return . Just,cutoff (n+1) . lift == lift . liftM Just0cutoff (n+1) . wrap == wrap . fmap (cutoff n)pCalling 'retract . cutoff n' is always terminating, provided each of the steps in the iteration is terminating.free Unfold a free monad from a seed.free-Unfold a free monad from a seed, monadically.freeThis is Prism' (Free f a) a in disguisepreview _Pure (Pure 3)Just 3 review _Pure 3 :: Free Maybe IntPure 3freeThis is  Prism' (Free f a) (f (Free f a)) in disguise,preview _Free (review _Free (Just (Pure 3)))Just (Just (Pure 3))review _Free (Just (Pure 3))Free (Just (Pure 3))freeLThis is not a true monad transformer. It is only a monad transformer "up to ".free3This violates the MonadPlus laws, handle with care.free5This violates the Alternative laws, handle with care.(C) 2008-2015 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> provisionalMPTCs, fundepsSafe 127=?@ASXfreeThe  g for a \ f.FormallyA g n is a free g for f# if every monad homomorphism from n to another monad m1 is equivalent to a natural transformation from f to m. Why Free?AEvery "free" functor is left adjoint to some "forgetful" functor.!If we define a forgetful functor UP from the category of monads to the category of functors that just forgets the g, leaving only the \. i.e. U (M,h,) = Mthen  is the left adjoint to U. being left adjoint to U+ means that there is an isomorphism between f -> m in the category of monads and f -> U m in the category of functors.(Morphisms in the category of monads are g5 homomorphisms (natural transformations that respect h and ).*Morphisms in the category of functors are \) homomorphisms (natural transformations).6Given this isomorphism, every monad homomorphism from  f to m0 is equivalent to a natural transformation from f to m;Showing that this isomorphism holds is left as an exercise.!In practice, you can just view a  f a as many layers of f wrapped around values of type a , where (f)0 performs substitution and grafts new layers of f# in for each of the free variables.[This can be very useful for modeling domain specific languages, trees, or other constructs.This instance of V is fairly naive about the encoding. For more efficient free monad implementation see Control.Monad.Free.Church, in particular note the 6 combinator. You may also want to take a look at the kan-extensions package ( 1http://hackage.haskell.org/package/kan-extensions)./A number of common monads arise as free monads,Given  data Empty a,  Empty is isomorphic to the  monad. p can be used to model a partiality monad where each layer represents running the computation for a while longer.free is the left inverse of  and   .  =   .  =  free Tear down a  g using iteration.freeLike  for applicative values.freeLike  for monadic values.free#Lift a natural transformation from f to g$ into a natural transformation from  f to  g.freehThe very definition of a free monad is that given a natural transformation you get a monad homomorphism.free Convert a  monad from Control.Monad.Free to a ) monad from Control.Monad.Trans.Free.freeCuts off a tree of computations at a given depth. If the depth is 0 or less, no computation nor monadic effects will take place.Some examples (n "e 0):'cutoff 0 _ == return Nothing&cutoff (n+1) . return == return . Just,cutoff (n+1) . lift == lift . liftM Just0cutoff (n+1) . wrap == wrap . fmap (cutoff n)pCalling 'retract . cutoff n' is always terminating, provided each of the steps in the iteration is terminating.free Unfold a free monad from a seed.free-Unfold a free monad from a seed, monadically.freeThis is Prism' (Free f a) a in disguisepreview _Pure (Pure 3)Just 3 review _Pure 3 :: Free Maybe IntPure 3freeThis is 9Prism (Free f a) (Free g a) (f (Free f a)) (g (Free g a)) in disguise,preview _Free (review _Free (Just (Pure 3)))Just (Just (Pure 3))review _Free (Just (Pure 3))Free (Just (Pure 3))freeLThis is not a true monad transformer. It is only a monad transformer "up to ".free3This violates the MonadPlus laws, handle with care.free5This violates the Alternative laws, handle with care.(C) 2011-2015 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> provisional"non-portable (rank-2 polymorphism)Safe =?@ASXХ free,The Church-encoded free monad for a functor f.It is asymptotically more efficient to use (f) for  than it is to (f) with . 6http://comonad.com/reader/2011/free-monads-for-less-2/free Tear down a  g using iteration.freeLike iter for monadic values.free is the left inverse of  and   .  =   .  =  free#Lift a natural transformation from f to g$ into a natural transformation from F f to F g.freehThe very definition of a free monad is that given a natural transformation you get a monad homomorphism.free-Convert to another free monad representation.free,Generate a Church-encoded free monad from a  monad.freeiImprove the asymptotic performance of code that builds a free monad with only binds and returns by using  behind the scenes.OThis is based on the "Free Monads for Less" series of articles by Edward Kmett: 4http://comonad.com/reader/2011/free-monads-for-less/Free monads for less  Part 1 6http://comonad.com/reader/2011/free-monads-for-less-2/Free monads for less  Part 2and  (http://www.iai.uni-bonn.de/~jv/mpc08.pdf9"Asymptotic Improvement of Computations over Free Monads" by Janis Voightlnder.freeCuts off a tree of computations at a given depth. If the depth is 0 or less, no computation nor monadic effects will take place.Some examples (n "e 0):'cutoff 0 _ == return Nothing&cutoff (n+1) . return == return . Just*cutoff (n+1) . lift == lift . liftM Just/cutoff (n+1) . wrap == wrap . fmap (cutoff n)Calling  .  nT is always terminating, provided each of the steps in the iteration is terminating.free3This violates the MonadPlus laws, handle with care.free5This violates the Alternative laws, handle with care.(C) 2008-2013 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> provisionalMPTCs, fundepsSafe2=?@A#freeThe coiterative comonadfree6This is the coiterative comonad generated by a comonadfree/Prepends a result to a coiterative computation. runCoiter . uncurry coiter == idfree9Extracts the first result from a coiterative computation. uncurry coiter . runCoiter == idfree Unfold a CoiterTJ comonad transformer from a cokleisli arrow and an initial comonadic seed. fg fg(C) 2008-2013 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> provisionalMPTCs, fundepsSafe 127=?@ASX# .freeThe . d of a functor f.FormallyA d v is a cofree d for f5 if every comonad homomorphism from another comonad w to v1 is equivalent to a natural transformation from w to f.A cofree1 functor is right adjoint to a forgetful functor.Cofree is a functor from the category of functors to the category of comonads that is right adjoint to the forgetful functor from the category of comonads to the category of functors that forgets how to  and , leaving you with only a \.eIn practice, cofree comonads are quite useful for annotating syntax trees, or talking about streams.>A number of common comonads arise directly as cofree comonads. For instance,. * forms the a comonad for a non-empty list.. ( b) is a product.. Identity forms an infinite stream.. ((->) b)'i describes a Moore machine with states labeled with values of type a, and transitions on edges of type b.Furthermore, if the functor f7 forms a monoid (for example, by being an instance of Z), the resulting d is also a g. See  5http://www.cs.appstate.edu/~johannp/jfp06-revised.pdf/Monadic Augment and Generalised Shortcut Fusion5 by Neil Ghani et al., Section 4.3 for more details.In particular, if  f a "a [a]%, the resulting data structure is a  'https://en.wikipedia.org/wiki/Rose_tree Rose tree'. For a practical application, check  ghttps://web.archive.org/web/20161208002902/http://www.cs.le.ac.uk/people/ak155/Papers/CALCO-07/GK07.pdf'Higher Dimensional Trees, Algebraically by Neil Ghani et al.0free9Use coiteration to generate a cofree comonad from a seed. 0 f = 2 (  f)1free!Like coiter for comonadic values.2free$Unfold a cofree comonad from a seed.3free1Unfold a cofree comonad from a seed, monadically.5free  . 5 = 6freeDThis is a lens that can be used to read or write from the target of .Using (^.) from the lens package: foo ^. 6 ==  fooFor more on lenses see the lens package on hackage 6 :: Lens' (. g a) a7freeCThis is a lens that can be used to read or write to the tails of a . d.Using (^.) from the lens package: foo ^. 7 == g fooFor more on lenses see the lens package on hackage 7 :: Lens' (. g a) (g (. g a))8free Construct an Lens into a . gd given a list of lenses into the base functor. When the input list is empty, this is equivalent to 6J. When the input list is non-empty, this composes the input lenses with 7 to walk through the . g before using 6* to get the element at the final location.For more on lenses see the lens package on hackage. telescoped :: [Lens' (g (. g a)) (. g a)] -> Lens' (. g a) a telescoped :: [Traversal' (g (. g a)) (. g a)] -> Traversal' (. g a) a telescoped :: [Getter (g (. g a)) (. g a)] -> Getter (. g a) a telescoped :: [Fold (g (. g a)) (. g a)] -> Fold (. g a) a telescoped :: [Setter' (g (. g a)) (. g a)] -> Setter' (. g a) a9free Construct an Lens into a . gU given a list of lenses into the base functor. The only difference between this and 8 is that 8 focuses on a single value, but this focuses on the entire remaining subtree. When the input list is empty, this is equivalent to J. When the input list is non-empty, this composes the input lenses with 7 to walk through the . g.For more on lenses see the lens package on hackage. telescoped :: [Lens' (g (. g a)) (. g a)] -> Lens' (. g a) (. g a) telescoped :: [Traversal' (g (. g a)) (. g a)] -> Traversal' (. g a) (. g a) telescoped :: [Getter (g (. g a)) (. g a)] -> Getter (. g a) (. g a) telescoped :: [Fold (g (. g a)) (. g a)] -> Fold (. g a) (. g a) telescoped :: [Setter' (g (. g a)) (. g a)] -> Setter' (. g a) (. g a):freeA  Traversal'# that gives access to all non-leaf a elements of a . g! a, where non-leaf is defined as x from  (x :< xs) where null xs is False.6Because this doesn't give access to all values in the . g%, it cannot be used to change types. 4shoots :: Traversable g => Traversal' (Cofree g a) aEN.B. On GHC < 7.9, this is slightly less flexible, as it has to use null (toList xs) instead.;freeA  Traversal' that gives access to all leaf a elements of a . g a, where leaf is defined as x from  (x :< xs) where null xs is True.6Because this doesn't give access to all values in the . g%, it cannot be used to change types. 4shoots :: Traversable g => Traversal' (Cofree g a) aEN.B. On GHC < 7.9, this is slightly less flexible, as it has to use null (toList xs) instead.QfreeThis is not a true d. transformer, but this instance is convenient.fg./0123456789:;./fg5012346789:;/5 !"#$%&'()*+,-."#$%&'(*), ! /012345678  9:;<=>?@/0134678  A/0134678 BBCD! EFGHIJKLMN/04#OPQRSTUVWXYZ[\]^_``abcdefghijklmnopqrstuvwxyz{|}~         !                     !                   !"#$%&'()*+,-./0123!456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWX!456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnoopqr8stuvwxyz{|}~_cq89                 !free-5.1.2-DlI3YrT06CpLsFy0Pzia8cControl.Alternative.FreeControl.Alternative.Free.FinalControl.Applicative.FreeControl.Applicative.Free.FastControl.Applicative.Free.FinalControl.Applicative.Trans.FreeControl.Comonad.Cofree.ClassControl.Comonad.Trans.CofreeControl.Monad.Free.ClassControl.Monad.Free.THControl.Monad.Trans.IterControl.Monad.Trans.Free.ApControl.Monad.Trans.FreeControl.Monad.Trans.Free.ChurchControl.Monad.Free.ApControl.Monad.FreeControl.Monad.Free.ChurchControl.Comonad.Trans.CoiterControl.Comonad.CofreeFreeData.Functor.Classes.Compat Control.Monadjoinimprove Data.FunctorIdentity Control.Arrow&&&Alt alternativesAltFApPureliftAltrunAlthoistAlt $fMonoidAlt$fSemigroupAlt$fAlternativeAlt$fAltAlt $fApplyAlt$fApplicativeAlt$fApplicativeAltF $fFunctorAlt $fFunctorAltF_runAltrunAprunAp_liftApiterAphoistAp retractAp $fComonadAp$fApplicativeAp $fApplyAp $fFunctorApunApASeqANilACons reduceASeq hoistASeq traverseASeq rebaseASeq_runApApTgetApTApFliftApTliftApOrunApFrunApTrunApT_hoistApFhoistApTtransApFtransApTjoinApT$fAlternativeApT $fApplyApT $fApplyApF$fApplicativeApT$fApplicativeApF $fFunctorApT $fFunctorApF ComonadCofreeunwrap$fComonadCofreefTracedT$fComonadCofreefStoreT$fComonadCofreefEnvT$fComonadCofreefIdentityT$fComonadCofreeConst(,)$fComonadCofree[]Tree$fComonadCofreeMaybeNonEmptyCofreeCofreeT runCofreeTCofreeF:<headFtailFcofree runCofree transCofreeTcoiterT $fDataCofreeF$fBitraversableCofreeF$fBifoldableCofreeF$fBifunctorCofreeF$fTraversableCofreeF$fFoldableCofreeF$fFunctorCofreeF $fDataCofreeT$fMonadZipCofreeT$fMonadTransCofreeT$fApplicativeCofreeT$fMonadCofreeT $fOrdCofreeT $fEqCofreeT $fReadCofreeT $fShowCofreeT$fComonadHoistCofreeT$fComonadEnveCofreeT$fComonadCofreefCofreeT$fComonadTransCofreeT$fTraversableCofreeT$fFoldableCofreeT$fComonadCofreeT$fFunctorCofreeT $fEqCofreeF $fOrdCofreeF $fShowCofreeF $fReadCofreeF$fGenericCofreeF$fGeneric1CofreeF MonadFreewrapliftFwrapT$fMonadFreefExceptT$fMonadFreefErrorT$fMonadFreefListT$fMonadFreefIdentityT$fMonadFreefMaybeT$fMonadFreefRWST$fMonadFreefRWST0$fMonadFreefWriterT$fMonadFreefWriterT0$fMonadFreefContT$fMonadFreefStateT$fMonadFreefStateT0$fMonadFreefReaderTmakeFree makeFree_ makeFreeCon makeFreeCon_ $fShowArgIterIterTrunIterTiterrunIterdelayretractfoldfoldM hoistIterTliftIternever untilJustcutoff interleave interleave_ $fDataIterT$fSemigroupIterT $fMonoidIterT$fMonadCatchIterT$fMonadThrowIterT$fMonadFreeIdentityIterT$fMonadContIterT$fMonadIOIterT$fMonadErroreIterT$fMonadStatesIterT$fMonadWriterwIterT$fMonadReadereIterT$fTraversable1IterT$fTraversableIterT$fFoldable1IterT$fFoldableIterT$fMonadTransIterT$fMonadPlusIterT$fAlternativeIterT$fMonadFixIterT $fBindIterT $fApplyIterT$fMonadFailIterT $fMonadIterT$fApplicativeIterT$fFunctorIterT $fReadIterT $fRead1IterT $fShowIterT $fShow1IterT $fOrdIterT $fOrd1IterT $fEqIterT $fEq1IterTFreeTrunFreeTFreeFrunFreefreeiterTiterTM hoistFreeT transFreeT joinFreeTiterM partialIterT intersperseTretractT intercalateT$fBitraversableFreeF$fBifoldableFreeF$fBifunctorFreeF$fTraversableFreeF$fFoldableFreeF$fFunctorFreeF $fOrd1FreeF $fOrd2FreeF $fEq1FreeF $fEq2FreeF $fRead1FreeF $fRead2FreeF $fShow1FreeF $fShow2FreeF$fTraversableFreeT$fFoldableFreeT$fMonadCatchFreeT$fMonadThrowFreeT$fMonadFreefFreeT$fMonadPlusFreeT$fAlternativeFreeT$fMonadContFreeT$fMonadErroreFreeT$fMonadStatesFreeT$fMonadWriterwFreeT$fMonadReaderrFreeT$fMonadIOFreeT$fMonadTransFreeT$fMonadFailFreeT $fMonadFreeT $fBindFreeT $fApplyFreeT$fApplicativeFreeT$fFunctorFreeT $fReadFreeT $fRead1FreeT $fShowFreeT $fShow1FreeT $fOrd1FreeT $fOrdFreeT $fEq1FreeT $fEqFreeT $fEqFreeF $fOrdFreeF $fShowFreeF $fReadFreeF$fGenericFreeF$fGeneric1FreeF foldFreeT$fMonadBasebFreeTFFTrunFTtoFTfromFTrunFhoistFTtransFTjoinFTfromFtoFimproveT$fMonadCatchFT$fMonadThrowFT$fMonadStatesFT$fMonadWriterwFT$fMonadReaderrFT $fMonadContFT$fMonadErroreFT $fMonadIOFT$fTraversableFT $fFoldableFT $fMonadPlusFT$fAlternativeFT$fMonadTransFT$fMonadFreefFT $fMonadFT$fBindFT$fApplicativeFT $fApplyFT $fFunctorFT$fOrdFT$fEqFT$fOrd1FT$fEq1FTiterA hoistFreefoldFreetoFreeTunfoldunfoldM_Pure_Free$fMonadFreefFree$fMonadContFree$fMonadErroreFree$fMonadStatesFree$fMonadReadereFree$fMonadWritereFree$fTraversable1Free$fTraversableFree$fFoldable1Free$fFoldableFree$fMonadTransFree$fMonadPlusFree$fAlternativeFree$fMonadFixFree $fMonadFree $fBindFree$fApplicativeFree $fApplyFree $fFunctorFree $fReadFree $fRead1Free $fShowFree $fShow1Free $fOrdFree $fOrd1Free$fEqFree $fEq1Free $fGenericFree$fGeneric1Free $fDataFreehoistFfoldF $fMonadContF$fMonadWriterwF$fMonadReadereF$fMonadStatesF $fMonadFreefF $fMonadTransF $fMonadPlusF$fTraversable1F $fFoldable1F$fTraversableF $fFoldableF $fMonadFixF$fMonadF$fBindF$fAlternativeF$fApplicativeF$fApplyF $fFunctorFCoiterCoiterT runCoiterTcoiter runCoiter $fDataCoiterT $fOrdCoiterT $fEqCoiterT $fReadCoiterT $fShowCoiterT$fComonadStoresCoiterT$fComonadTracedmCoiterT$fComonadHoistCoiterT$fComonadEnveCoiterT$fComonadCofreeIdentityCoiterT$fComonadTransCoiterT$fTraversableCoiterT$fFoldableCoiterT$fComonadCoiterT$fFunctorCoiterT$fRead1CoiterT$fShow1CoiterT $fOrd1CoiterT $fEq1CoiterTcoiterW hoistCofreesection_extract_unwrap telescoped telescoped_shootsleaves$fComonadTracedmCofree$fComonadStoresCofree$fComonadEnveCofree$fComonadHoistCofree$fTraversable1Cofree$fTraversableCofree$fFoldable1Cofree$fFoldableCofree $fOrd1Cofree $fOrdCofree $fEq1Cofree $fEqCofree $fReadCofree $fRead1Cofree $fShowCofree $fShow1Cofree$fApplicativeCofree$fComonadApplyCofree $fApplyCofree$fMonadZipCofree $fMonadCofree$fComonadTransCofree$fComonadCofree$fExtendCofree$fFunctorCofree$fDistributiveCofree$fComonadCofreefCofree$fGenericCofree$fGeneric1Cofree $fDataCofreebaseGHC.Base Alternative ApplicativeFunctorpure<*>fmap Data.FoldableFoldableghc-prim GHC.TypesIntmaximum#comonad-5.0.5-7SyeUF1VdQ4WC83bueKCLControl.ComonadComonad>>=MonadreturnmkOpNameusesTVmkArgmapRetunifyT unifyCapturedliftConconstructorNamesliftDecgenFree genFreeConmappendData.Functor.Classes showsBinary1 showsUnary1 showsUnary readsBinary1 readsUnary1 readsUnaryshowsBinaryWithshowsUnaryWithreadBinaryWithreadsBinaryWith readUnaryWithreadsUnaryWithreadData readsData showsPrec2liftReadListPrec2DefaultliftReadList2Default readPrec2 readsPrec2compare2eq2 showsPrec1liftReadListPrecDefaultliftReadListDefault readPrec1 readsPrec1compare1eq1Eq1liftEqOrd1 liftCompareRead1 liftReadsPrec liftReadList liftReadPrecliftReadListPrecShow1 liftShowsPrec liftShowListEq2liftEq2Ord2 liftCompare2Read2liftReadsPrec2 liftReadList2 liftReadPrec2liftReadListPrec2Show2liftShowsPrec2 liftShowList2Data.Functor.Identitytransformers-0.5.5.0Control.Monad.Trans.Classliftid GHC.MaybeJustNothing.liftMGHC.Listiterate!!<$Maybeextract duplicateData.Functor.ConstConstControl.CategoryControl.Comonad.Trans.Classlower