packages feed

streaming 0.1.0.0 → 0.1.0.1

raw patch · 3 files changed

+76/−7 lines, 3 files

Files

Streaming.hs view
@@ -1,10 +1,14 @@ {-#LANGUAGE RankNTypes #-} module Streaming     (+   -- * Free monad transformer+   -- $stream+   Stream,     -- * Constructing a 'Stream' on a base functor-   construct,    unfold,    for,+   construct,+       -- * Transforming streams    maps,    maps',@@ -25,8 +29,7 @@    chunksOf,    concats, -   -- * Types-   Stream,+   -- * Useful functors    Of (..),    lazily,    strictly,@@ -41,6 +44,35 @@ import Control.Monad.Morph (MFunctor(..)) import Control.Monad import Control.Monad.Trans+++{- $stream++    The 'Stream' data type is equivalent to @FreeT@ and can represent any effectful+    succession of steps, where the form of the steps or 'commands' is +    specified by the first (functor) parameter. ++> data Stream f m r = Step !(f (Stream f m r)) | Delay (m (Stream f m r)) | Return r++    In the simplest case, the base functor is @ (,) a @. Here the news +    or /command/ at each step is an individual element of type @ a @, +    i.e. a @yield@ statement.  In 'Streaming.Prelude', @(a,b)@ is+    replaced by the left-strict pair @Of a b@. Various operations are+    defined for types like++> Stream (Of a) m r                   -- a producer in the pipes sense +>                                        -- i.e. an effectful, streaming [a], or rather ([a],r) +> Stream (Of a) m (Stream (Of a) m r) -- the effectful splitting of a producer+>                                        -- i.e. an effectful ([a],[a]) or rather ([a],([a],r))+> Stream (Stream (Of a) m) m r        -- successive, segmentation of a producer+                                         -- i.e. [[a]], or ([a],([a],([a]... r)))+    and so on. But of course any functor can be used.++    To avoid breaking reasoning principles, the constructors +    should not be used directly. A pattern-match should go by way of 'inspect' +    \- or, in the producer case, 'Streaming.Prelude.next'+    The constructors are exported by the 'Internal' module.+-}   
Streaming/Internal.hs view
@@ -1,6 +1,32 @@ {-# LANGUAGE RankNTypes, StandaloneDeriving,DeriveDataTypeable, BangPatterns #-} {-# LANGUAGE UndecidableInstances #-} -- for show, data instances-module Streaming.Internal where+module Streaming.Internal (+    -- * The free monad transformer+    -- $stream+    Stream (..)+    +    -- * Introducing a stream+    , construct +    , unfold +    +    -- * Eliminating a stream+    , destroy +    , concats +    , intercalates +    , iterT +    , iterTM +    +    -- * Inspecting a stream step by step+    , inspect +    +    -- * Transforming streams+    , maps +    , mapsM +    +    -- *  Splitting streams+    , chunksOf +    , split +   ) where  import Control.Monad import Control.Monad.Trans@@ -15,9 +41,12 @@ import Data.Data ( Data, Typeable ) import Prelude hiding (splitAt) -{-| 'Stream' data type is equivalent to @FreeT@ and can represent any effectful-    succession of steps, where the steps are specified by the first 'functor' parameter. +{- $stream +    The 'Stream' data type is equivalent to @FreeT@ and can represent any effectful+    succession of steps, where the form of the steps or 'commands' is +    specified by the first (functor) parameter. + > data Stream f m r = Step !(f (Stream f m r)) | Delay (m (Stream f m r)) | Return r      The /producer/ concept uses the simple functor @ (a,_) @ \- or the stricter @@ -87,6 +116,14 @@       Step f    -> Step (fmap loop f)   {-# INLINABLE hoist #-}     +instance Functor f => MMonad (Stream f) where+  embed phi = loop where+    loop stream = case stream of+      Return r -> Return r+      Delay m  -> phi m >>= loop+      Step f   -> Step (fmap loop f)+  {-# INLINABLE embed #-}   +    instance (MonadIO m, Functor f) => MonadIO (Stream f m) where   liftIO = Delay . liftM Return . liftIO   {-# INLINE liftIO #-}
streaming.cabal view
@@ -1,5 +1,5 @@ name:                streaming-version:             0.1.0.0+version:             0.1.0.1 cabal-version:       >=1.10 build-type:          Simple synopsis:            A general free monad transformer optimized for streaming applications.