Skip to content
Browse files

Initial commit

  • Loading branch information...
0 parents commit 4c7155f8df485619079eca53a23facf7d73d35d5 @jberryman committed Jul 10, 2011
Showing with 183 additions and 0 deletions.
  1. +70 −0 Control/Concurrent/Chan/Split.hs
  2. +9 −0 Data/Cofunctor.lhs
  3. +30 −0 LICENSE
  4. +74 −0 chan-split.cabal
70 Control/Concurrent/Chan/Split.hs
@@ -0,0 +1,70 @@
+{-# LANGUAGE GADTs #-}
+module Control.Concurrent.Chan.Split (
+ -- * Chan pairs
+ newChanPair
+ , InChan()
+ , OutChan()
+ -- * Write operations
+ , writeChan
+ , writeList2Chan
+ -- * Read operations
+ , readChan
+ , getChanContents
+ , dupChan
+
+ -- , chanPlus
+
+ ) where
+
+import qualified Control.Concurrent.Chan as C
+import Data.Cofunctor
+
+
+-- TODO: test performance of this with and without fmaped / cofmaped values in
+-- comparison with standard Chan. Test to see if we can improve performance
+-- using special constructor for fmaped / cofmaped version
+
+
+-- | The "write side" of a chan pair
+data InChan i where
+ InChan :: C.Chan a -> (i -> a) -> InChan i
+
+-- | The "read side" of a chan pair
+data OutChan o where
+ OutChan :: C.Chan a -> (a -> o) -> OutChan o
+
+-- | Create corresponding read and write ends of a chan pair. Writes to the
+-- 'InChan' side can be read on the 'OutChan' side.
+newChanPair :: IO (InChan a, OutChan a)
+newChanPair = undefined
+
+
+
+
+
+-- | Write a value to an 'InChan'.
+writeChan :: InChan a -> a -> IO ()
+writeChan = undefined
+
+-- | Write an entire list of items to an 'InChan'.
+writeList2Chan :: InChan a -> [a] -> IO ()
+writeList2Chan = undefined
+
+
+-- | Read the next value from the 'OutChan'.
+readChan :: OutChan a -> IO a
+readChan = undefined
+
+-- | Return a lazy list representing the contents of the supplied OutChan, much
+-- like System.IO.hGetContents.
+getChanContents :: OutChan a -> IO [a]
+getChanContents = undefined
+
+
+
+-- | Duplicate an 'OutChan': the duplicate channel begins empty, but data
+-- written to the corresponding 'InChan' will appear in both, i.e. consuming a
+-- value from the copy will have no affect on the values in the original
+-- OutChan.
+dupChan :: OutChan a -> IO (OutChan a)
+dupChan = undefined
9 Data/Cofunctor.lhs
@@ -0,0 +1,9 @@
+> module Data.Cofunctor
+> where
+
+
+This doesn't seem to be a popular class, unfortunately but it's useful for us
+here: it lets us transform a Mailbox/sink/processor of one input type to another
+
+> class Cofunctor f where
+> cofmap :: (b -> a) -> f a -> f b
30 LICENSE
@@ -0,0 +1,30 @@
+Copyright (c)2011, Brandon Simmons
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of Brandon Simmons nor the names of other
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
74 chan-split.cabal
@@ -0,0 +1,74 @@
+-- chan-split.cabal auto-generated by cabal init. For additional
+-- options, see
+-- http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#pkg-descr.
+-- The name of the package.
+Name: chan-split
+
+-- The package version. See the Haskell package versioning policy
+-- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for
+-- standards guiding when and how versions should be incremented.
+Version: 0.1
+
+-- A short (one-line) description of the package.
+Synopsis: Concurrent chans split into readable and writable pairs with useful Functor instances
+
+-- A longer description of the package.
+Description: A wrapper around Control.Concurrent.Chan that splits a Chan
+ into a pair, one of which allows only read operations, the
+ other write operations.
+ .
+ This makes code easier to reason about, allows us to define
+ useful instances ('Functor' and 'Cofunctor') on the chan
+ pairs.
+ .
+ When used alongside standard Chans, the module can be
+ imported qualified like:
+ .
+ > import qualified Control.Concurrent.Chan.Split as S
+ .
+ Note, we do not implement the deprecated unGetChan and
+ isEmptyChan functions.
+ .
+ This module is used internally by the simple-actors package.
+
+-- The license under which the package is released.
+License: BSD3
+
+-- The file containing the license text.
+License-file: LICENSE
+
+-- The package author(s).
+Author: Brandon Simmons
+
+-- An email address to which users can send suggestions, bug reports,
+-- and patches.
+Maintainer: brandon.m.simmons@gmail.com
+
+-- A copyright notice.
+-- Copyright:
+
+Category: Concurrency
+
+Build-type: Simple
+
+-- Extra files to be distributed with the package, such as examples or
+-- a README.
+-- Extra-source-files:
+
+-- Constraint on the version of Cabal needed to build this package.
+Cabal-version: >=1.2
+
+
+Library
+ -- Modules exported by the library.
+ Exposed-modules: Control.Concurrent.Chan.Split, Data.Cofunctor
+
+ -- Packages needed in order to build this package.
+ Build-depends: base >= 4 && < 5
+
+ -- Modules not exported by this package.
+ -- Other-modules:
+
+ -- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source.
+ -- Build-tools:
+

0 comments on commit 4c7155f

Please sign in to comment.
Something went wrong with that request. Please try again.