_X      experimental6Sebastian Fischer <mailto:sebf@informatik.uni-kiel.de>"@Derives monadic datatypes and instances for explicit sharing as B well as conversion. Combines the other three derivations which > provide the same functionality split into different parts. DYou usually need the following preamble when deriving monadic code:   {-# LANGUAGE TemplateHaskell  , KindSignatures  , MultiParamTypeClasses  , FlexibleInstances  #-}  import Control.Monad.Sharing  import Data.Monadic.Derive  import Data.DeriveTH .If your types contain lists, you also need to   import Data.Monadic.List 2With this prerequisites, you can derive a monadic  type by  $(derive monadic ''Maybe) 8Generates a monadic datatype and corresponding con- and 1 destructor functions from a Haskell datatype. For example, the datatype  ! data Maybe a = Nothing | Just a 9can be translated into its monadic counterpart by typing   $(derive makeMData ''Maybe) +This call generates the following datatype  * data MMaybe m a = MNothing | MJust (m a) ;and the following auxiliary functions for constructing and  matching monadic values:  ' mNothing :: Monad m => m (MMaybe m a)  mNothing = return MNothing  + mJust :: Monad m => m a -> m (MMaybe m a)  mJust a = return (MJust a) H matchMMaybe :: Monad m => m (MMaybe m a) -> m b -> (m a -> m b) -> m b M matchMMaybe x n j = x >>= \x -> case x of { MNothing -> n; MJust a -> j a }  Generates a  Shareable" instance for a monadic datatype. For example the call  ! $(derive makeShareable ''Maybe) "generates the following instance: B instance (Monad m, Shareable m a) => Shareable (Maybe m a) where - shareArgs fun MNothing = return MNothing 5 shareArgs fun (MJust a) = fun a >>= \a -> mJust a  Generates  Convertible* instances to convert between monadic and  non-monadic datatypes. For example, the call  # $(derive makeConvertible ''Maybe) #generates the following instances: ( instance (Monad m, Convertible m a a') 6 => Convertible m (Maybe a) (MMaybe m a') where $ convArgs fun Nothing = mNothing ) convArgs fun (Just a) = mJust (fun a)  ( instance (Monad m, Convertible m a' a) 6 => Convertible m (MMaybe m a') (Maybe a) where + convArgs fun MNothing = return Nothing B convArgs fun (MJust a) = (a >>= fun) >>= \a -> return (Just a)  !"#$%&'()*+,-./012345678 experimental6Sebastian Fischer <mailto:sebf@informatik.uni-kiel.de> ;Interface for convertible datatypes. The provided function  9 is supposed to map the given function on every argument B of the given value and combine the results to give the converted  value. We provide instances of the  class for some predefined , Haskell types. For flat types the function  just returns A its argument which has no arguments to which the given function  could be applied.  ?Interface of shareable nested monadic data types. The provided  function  0 is supposed to map the given function on every  monadic argument. We provide instances of the   class for some predefined , Haskell types. For flat types the function   just returns A its argument which has no arguments to which the given function  could be applied. 3Interface of monads that support explicit sharing. <Yields an action that returns the same results as the given C action but whose effects are only executed once. Especially, when B the resulting action is duplicated it returns the same result at  every occurrence. *Converts a convertible value recursively. 9AAn instance to convert lists with monadic elements into ordinary  lists. :>An instance to convert ordinary lists into lists with monadic  elements. ;-An instance for lists with monadic elements.        experimental6Sebastian Fischer <mailto:sebf@informatik.uni-kiel.de><=>?@A=Continuation-based, store-passing implementation of explicit & sharing. It is an inlined version of ContT (ReaderT Store m) 8 where the result type of continuations is polymorphic. BCRuns a computation of type Lazy m a with given continuation and  store. ALifts all monadic effects to the top-level and unwraps the monad # transformer for explicit sharing. DEFGHIJ>DEFGH>DEFGH experimental6Sebastian Fischer <mailto:sebf@informatik.uni-kiel.de>KLMNOAMonad transformer that adds explicit sharing capability to every  monad. PQALifts all monadic effects to the top-level and unwraps the monad # transformer for explicit sharing. RSTUVWXY experimental6Sebastian Fischer <mailto:sebf@informatik.uni-kiel.de>0Z[\]^_`abcdefghijklmnopqrstuvwxyz{|}~    experimental0Sebastian Fischer (sebf\@informatik.uni-kiel.de) >Data type for lists where both the head and tail are monadic. The empty monadic list. %Constructs a non-empty monadic list. !Checks if monadic list is empty. -Yields the head of a monadic list. Relies on ` instance ( to provide a failing implementation of Z. -Yields the tail of a monadic list. Relies on ` instance ( to provide a failing implementation of Z. #This instance enables the function Control.Monad.Sharing.convert @ to transform nested monadic lists into ordinary Haskell lists. #This instance enables the function Control.Monad.Sharing.convert @ to transform ordinary Haskell lists into nested monadic lists. DThis instance allows to use nested monadic lists as argument to the  Control.Monad.Sharing.share combinator.  experimental6Sebastian Fischer <mailto:sebf@informatik.uni-kiel.de>0Z[\]^_`abcdefghijklmnopqrstuvwxyz{|}~         !"#$%&'()*+,-./0123456789:;<=>?@ABCDDEEFGHIJKLMNOPPQRSHTUVWXYZ[$\]$\^$\_$\`$\a$\b$cd$ce$cf$cg$ch$ci$cj$ck$cl$cm$cn$co$cp$cq$cr$cs$ct$cu$cv$cw$cx$cy$cz$c{$c|$c}$c~$c$c$c$c$c$\explicit-sharing-0.6Data.Monadic.DeriveControl.Monad.Sharing.ClassesControl.Monad.Sharing Control.Monad.Sharing.FirstOrderData.Monadic.List(Control.Monad.Sharing.Implementation.CPS/Control.Monad.Sharing.Implementation.FirstOrdermonadic makeMData makeShareablemakeConvertible ConvertibleconvArgsMBoolMCharMInt Shareable shareArgsSharingshareconvertLazyevalLazyListConsNilnilconsisEmptyfirstrestConv typeParamName branchResName funArgNamebase Data.MaybeMaybeconvDataconvName convQConsconvCons convBTypeconvType makeCFunTmakeTypemakeCFun makeMatchFunT branchTypeC branchType makeMatchFunmakeAlt shareableInstmakeShareArgsRule convInsts makeConvToM makeConvFromMfromName isSymbolCharconsNameconsArgstVar isBangTypeconDecl$fConvertiblem[][]$fConvertiblem[][]0$fShareablem[]UntypedStore nextLabelheapfromLazyrunLazy emptyStore freshLabel lookupValue storeValuememotypedLabeled WithFreshLiftedSevalSgnfhnfrun labelArgs.:setLabelbindGHC.Basefail>>=>>returnMonadFunctor Control.Monad MonadPlusapliftM5liftM4liftM3liftM2liftMunlesswhen replicateM_ replicateMfoldM_foldM zipWithM_zipWithM mapAndUnzipMjoinforever<=<>=>msumforM_forMfilterMguardmapM_mapM sequence_sequence=<<mplusmzerofmap$fConvertiblemList[]$fConvertiblem[]List$fShareablemList