packages feed

explicit-sharing 0.4.0 → 0.4.0.1

raw patch · 5 files changed

+94/−80 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

Control/Monad/Sharing.hs view
@@ -1,12 +1,13 @@--- | Module      : Control.Monad.Sharing--- | Copyright   : Chung-chieh Shan, Oleg Kiselyov, and Sebastian Fischer--- | License     : PublicDomain--- |--- | Maintainer  : Sebastian Fischer (sebf@informatik.uni-kiel.de)--- | Stability   : experimental--- |--- | This library provides an interface to monads that support explicit--- | sharing.+-- | +-- Module      : Control.Monad.Sharing+-- Copyright   : Chung-chieh Shan, Oleg Kiselyov, and Sebastian Fischer+-- License     : PublicDomain+-- Maintainer  : Sebastian Fischer <mailto:sebf@informatik.uni-kiel.de>+-- Stability   : experimental+-- +-- This library provides an interface to monads that support explicit+-- sharing. A project website with tutorials can be found at+-- <http://sebfisch.github.com/explicit-sharing>. module Control.Monad.Sharing (    module Control.Monad,
Control/Monad/Sharing/Classes.hs view
@@ -1,24 +1,20 @@ {-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, Rank2Types #-} --- | Module      : Control.Monad.Sharing.Classes--- | Copyright   : Chung-chieh Shan, Oleg Kiselyov, and Sebastian Fischer--- | License     : PublicDomain--- |--- | Maintainer  : Sebastian Fischer (sebf@informatik.uni-kiel.de)--- | Stability   : experimental--- |--- | This library provides type classes for explicit sharing of--- | monadic effects.+-- | +-- Module      : Control.Monad.Sharing.Classes+-- Copyright   : Chung-chieh Shan, Oleg Kiselyov, and Sebastian Fischer+-- License     : PublicDomain+-- Maintainer  : Sebastian Fischer <mailto:sebf@informatik.uni-kiel.de>+-- Stability   : experimental+-- +-- This library provides type classes for explicit sharing of monadic+-- effects. Usually you don't need to import this library as it is+-- reexported by the module 'Control.Monad.Sharing'. You may want to+-- do so, however, when writing your own implementation of explicit+-- sharing. module Control.Monad.Sharing.Classes ( -  Sharing(..), --  -- | We provide instances of the @Trans@ class for some predefined-  -- | Haskell types. For flat types the function @trans@ just returns-  -- | its argument which has no arguments to which the given function-  -- | could be applied.--  Trans(..), eval+  Sharing(..), Trans(..), eval   ) where @@ -27,26 +23,34 @@ -- | Interface of monads that support explicit sharing. class Sharing m  where-  -- | Yields an action that returns the same results as the given-  -- | action but whose effects are only executed once. Especially,-  -- | when the resulting action is duplicated it returns the same-  -- | result at every occurrence.+  -- | +  -- Yields an action that returns the same results as the given+  -- action but whose effects are only executed once. Especially, when+  -- the resulting action is duplicated it returns the same result at+  -- every occurrence.   share :: Trans m a a => m a -> m (m a) --- | Interface to transform nested monadic data types. The provided--- | function @trans@ is supposed to map the given function on every--- | monadic argument. The result of @trans@ may be of the same type--- | as the argument but can also be of a different type, e.g. to--- | convert a value with nested monadic arguments to a corresponding--- | value without.+-- |+-- Interface to transform nested monadic data types. The provided+-- function 'trans' is supposed to map the given function on every+-- monadic argument. The result of 'trans' may be of the same type as+-- the argument but can also be of a different type, e.g. to convert a+-- value with nested monadic arguments to a corresponding value+-- without.+-- +-- We provide instances of the 'Trans' class for some predefined+-- Haskell types. For flat types the function 'trans' just returns its+-- argument which has no arguments to which the given function could+-- be applied. class Trans m a b  where   trans :: (forall c d . Trans m c d => m c -> m (m d)) -> a -> m b --- | Lifts all monadic effects in nested monadic values to the top--- | level. If @m@ is a monad for non-determinism and the argument a--- | data structure with nested non-determinism then the result--- | corresponds to the normal form of the argument.+-- |+-- Lifts all monadic effects in nested monadic values to the top+-- level. If @m@ is a monad for non-determinism and the argument a+-- data structure with nested non-determinism then the result+-- corresponds to the normal form of the argument. eval :: (Monad m, Trans m a b) => a -> m b eval = trans (\a -> liftM return (a >>= eval)) @@ -95,9 +99,10 @@  where   trans f = mapM f --- | An instance for lists with monadic elements that lifts all--- | monadic effects to the top level and yields a list with--- | non-monadic elements.+-- |+-- An instance for lists with monadic elements that lifts all monadic+-- effects to the top level and yields a list with non-monadic+-- elements. instance (Monad m, Trans m a a) => Trans m [m a] [a]  where   trans f = mapM (join . f)
Control/Monad/Sharing/Implementation/CPS.hs view
@@ -6,17 +6,17 @@  {-# OPTIONS -fno-warn-name-shadowing #-} --- | Module      : Control.Monad.Sharing.Implementation.CPS--- | Copyright   : Chung-chieh Shan, Oleg Kiselyov, and Sebastian Fischer--- | License     : PublicDomain--- |--- | Maintainer  : Sebastian Fischer (sebf@informatik.uni-kiel.de)--- | Stability   : experimental+-- | +-- Module      : Control.Monad.Sharing.Implementation.CPS+-- Copyright   : Chung-chieh Shan, Oleg Kiselyov, and Sebastian Fischer+-- License     : PublicDomain+-- Maintainer  : Sebastian Fischer (sebf\@informatik.uni-kiel.de)+-- Stability   : experimental -- |--- | Implements explicit sharing by passing a heap using a state monad--- | implemented by a combination of a continuation- with a reader--- | monad. The definitions are inlined and hand-optimized to increase--- | performance.+-- Implements explicit sharing by passing a heap using a state monad+-- implemented by a combination of a continuation- with a reader+-- monad. The definitions are inlined and hand-optimized to increase+-- performance. module Control.Monad.Sharing.Implementation.CPS (    Lazy, evalLazy@@ -32,18 +32,21 @@  import qualified Data.IntMap as M --- | Continuation-based, store-passing implementation of explicit--- | sharing. It is an inlined version of @ContT (ReaderT Store m)@--- | where the result type of continuations is polymorphic.+-- |+-- Continuation-based, store-passing implementation of explicit+-- sharing. It is an inlined version of @ContT (ReaderT Store m)@+-- where the result type of continuations is polymorphic. newtype Lazy m a = Lazy { -  -- | Runs a computation of type @Lazy m a@ with given continuation-  -- | and store.+  -- |+  -- Runs a computation of type @Lazy m a@ with given continuation and+  -- store.   fromLazy :: forall w . (a -> Store -> m w) -> Store -> m w  } --- | Lifts all monadic effects to the top-level and unwraps the monad--- | transformer for explicit sharing.+-- |+-- Lifts all monadic effects to the top-level and unwraps the monad+-- transformer for explicit sharing. evalLazy :: (Monad m, Trans (Lazy m) a b) => Lazy m a -> m b evalLazy m = runLazy (m >>= eval) 
Data/Monadic/List.hs view
@@ -1,15 +1,15 @@ {-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-} --- | Module      : Data.Monadic.List--- | Copyright   : Chung-chieh Shan, Oleg Kiselyov, and Sebastian Fischer--- | License     : PublicDomain -- |--- | Maintainer  : Sebastian Fischer (sebf@informatik.uni-kiel.de)--- | Stability   : experimental--- |--- | This library provides lists with monadic head and tail as an--- | example for nested monadic data that can be used with the--- | combinator @share@ for explicit sharing.+-- Module      : Data.Monadic.List+-- Copyright   : Chung-chieh Shan, Oleg Kiselyov, and Sebastian Fischer+-- License     : PublicDomain+-- Maintainer  : Sebastian Fischer (sebf\@informatik.uni-kiel.de)+-- Stability   : experimental+-- +-- This library provides lists with monadic head and tail as an+-- example for nested monadic data that can be used with the+-- combinator @share@ for explicit sharing. module Data.Monadic.List (    List(..), nil, cons, isEmpty, first, rest@@ -37,32 +37,37 @@                   Nil      -> return True                   Cons _ _ -> return False --- | Yields the head of a monadic list. Relies on @MonadPlus@ instance--- | to provide a failing implementation of @fail@.+-- |+-- Yields the head of a monadic list. Relies on 'MonadPlus' instance+-- to provide a failing implementation of 'fail'. first :: MonadPlus m => m (List m a) -> m a first ml = do Cons x _ <- ml; x --- | Yields the tail of a monadic list. Relies on @MonadPlus@ instance--- | to provide a failing implementation of @fail@.+-- |+-- Yields the tail of a monadic list. Relies on 'MonadPlus' instance+-- to provide a failing implementation of 'fail'. rest :: MonadPlus m => m (List m a) -> m (List m a) rest ml = do Cons _ xs <- ml; xs --- | This instance allows to use nested monadic lists as argument to--- | the @Control.Monad.Sharing.share@ combinator.+-- |+-- This instance allows to use nested monadic lists as argument to the+-- 'Control.Monad.Sharing.share' combinator. instance (Monad m, Trans m a b) => Trans m (List m a) (List m b)  where   trans _ Nil         = return Nil   trans f (Cons x xs) = return Cons `ap` f x `ap` f xs --- | This instance enables the function @Control.Monad.Sharing.eval@--- | to transform nested monadic lists into ordinary Haskell lists.+-- |+-- This instance enables the function 'Control.Monad.Sharing.eval' to+-- transform nested monadic lists into ordinary Haskell lists. instance (Monad m, Trans m a b) => Trans m (List m a) [b]  where   trans _ Nil         = return []   trans f (Cons x xs) = return (:) `ap` join (f x) `ap` join (f xs) --- | This instance enables the function @Control.Monad.Sharing.eval@--- | to transform ordinary Haskell lists into nested monadic lists.+-- |+-- This instance enables the function 'Control.Monad.Sharing.eval' to+-- transform ordinary Haskell lists into nested monadic lists. instance (Monad m, Trans m a b) => Trans m [a] (List m b)  where   trans _ []     = return Nil
explicit-sharing.cabal view
@@ -1,5 +1,5 @@ Name:          explicit-sharing-Version:       0.4.0+Version:       0.4.0.1 Cabal-Version: >= 1.6 Synopsis:      Explicit Sharing of Monadic Effects Description: