VPW      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 mdata ''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 shareable ''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 convertible ''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) $%&'()*+,-./0123456789:;<= experimental6Sebastian Fischer <mailto:sebf@informatik.uni-kiel.de>;Interface for convertible datatypes. The provided function  convArgs9 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 convArgs 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. >AAn 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>ABCDEFG=Continuation-based, store-passing implementation of explicit & sharing. It is an inlined version of ContT n (Reader Store). HIRuns a computation of type Lazy n a with given continuation and  store. JKLMNOP ABCKLMNP ABBCKLMNP 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 Q instance ( to provide a failing implementation of R. -Yields the tail of a monadic list. Relies on Q instance ( to provide a failing implementation of R. S#This instance enables the function Control.Monad.Sharing.convert @ to transform nested monadic lists into ordinary Haskell lists. T#This instance enables the function Control.Monad.Sharing.convert @ to transform ordinary Haskell lists into nested monadic lists. UDThis instance allows to use nested monadic lists as argument to the  Control.Monad.Sharing.share combinator.  experimental6Sebastian Fischer <mailto:sebf@informatik.uni-kiel.de>VWX5RYZ[\]Q^_`abcdefghijklmnopqrstuvwxyz{|}~          !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKKLLMNOOPQRSTUVW+XY+Z[\]^_`a+Zb+Zc+Zd+Ze+Zf+Xg+Xh+Xi+Xj+Xk+Xl+Xm+Xn+Xo+Xp+Xq+Xr+Xs+Xt+Xu+Xv+Xw+Xx+Xy+Xz+X{+X|+X}+X~+X+X+X+X+X+X+X+X+X+Zexplicit-sharing-0.9Data.Monadic.DeriveControl.Monad.Sharing.ClassesControl.Monad.SharingData.Monadic.List(Control.Monad.Sharing.Implementation.CPS derive-2.4.2 Data.DeriveTHderivemonadicmdata shareable convertibleNondetfailure? ConvertibleconvertMBoolMCharMInt Shareable shareArgsSharingsharecollectListConsNilnilconsisEmptyfirstrest hasResultresults resultDist unsafeResults resultListConv typeParamName branchResName funArgNamebase Data.MaybeMaybeconvDataconvName convQConsconvCons convBTypeconvType makeCFunTmakeTypemakeCFun makeMatchFunT branchTypeC branchType makeMatchFunmakeAlt shareableInstmakeShareArgsRule convInsts makeConvToM makeConvFromMfromName isSymbolCharconsNameconsArgstVar isBangTypeconDecl$fConvertiblem[][]$fConvertiblem[][]0$fShareablem[]UntypedStore nextLabelheapLazyfromLazyrunLazy emptyStore freshLabel lookupValue storeValuememotyped Control.Monad MonadPlusGHC.Basefail$fConvertiblemList[]$fConvertiblem[]List$fShareablemList UnsafeResultsUnsafeunsafe>>=>>returnMonadFunctormfilterapliftM5liftM4liftM3liftM2liftMunlesswhen replicateM_ replicateMfoldM_foldM zipWithM_zipWithM mapAndUnzipMjoinvoidforever<=<>=>msumforM_forMfilterMguardmapM_mapM sequence_sequence=<<mplusmzerofmap