packages feed

chan-split 0.1.3 → 0.2.0

raw patch · 4 files changed

+58/−45 lines, 4 filesdep +cofunctorPVP ok

version bump matches the API change (PVP)

Dependencies added: cofunctor

API changes (from Hackage documentation)

- Control.Concurrent.Chan.Class: class ReadableChan c
- Control.Concurrent.Chan.Class: class WritableChan c
- Control.Concurrent.Chan.Class: instance ReadableChan Chan
- Control.Concurrent.Chan.Class: instance ReadableChan MVar
- Control.Concurrent.Chan.Class: instance WritableChan Chan
- Control.Concurrent.Chan.Class: instance WritableChan MVar
- Control.Concurrent.Chan.Split: instance ReadableChan OutChan
- Control.Concurrent.Chan.Split: instance WritableChan InChan
- Control.Concurrent.Chan.Split: newSplitChan :: IO (InChan a, OutChan a)
- Data.Cofunctor: class Cofunctor f
- Data.Cofunctor: cofmap :: Cofunctor f => (b -> a) -> f a -> f b
+ Control.Concurrent.Chan.Class: class SplitChan i o => NewSplitChan i o
+ Control.Concurrent.Chan.Class: class SplitChan i o | i -> o, o -> i
+ Control.Concurrent.Chan.Class: instance NewSplitChan Chan Chan
+ Control.Concurrent.Chan.Class: instance NewSplitChan MVar MVar
+ Control.Concurrent.Chan.Class: instance SplitChan Chan Chan
+ Control.Concurrent.Chan.Class: instance SplitChan MVar MVar
+ Control.Concurrent.Chan.Class: newSplitChan :: NewSplitChan i o => IO (i a, o a)
+ Control.Concurrent.Chan.Split: instance NewSplitChan InChan OutChan
+ Control.Concurrent.Chan.Split: instance SplitChan InChan OutChan
- Control.Concurrent.Chan.Class: readChan :: ReadableChan c => c a -> IO a
+ Control.Concurrent.Chan.Class: readChan :: SplitChan i o => o a -> IO a
- Control.Concurrent.Chan.Class: writeChan :: WritableChan c => c a -> a -> IO ()
+ Control.Concurrent.Chan.Class: writeChan :: SplitChan i o => i a -> a -> IO ()
- Control.Concurrent.Chan.Class: writeList2Chan :: WritableChan c => c a -> [a] -> IO ()
+ Control.Concurrent.Chan.Class: writeList2Chan :: SplitChan i o => i a -> [a] -> IO ()

Files

Control/Concurrent/Chan/Class.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-} module Control.Concurrent.Chan.Class     where @@ -13,22 +14,26 @@ -}  --- | A class for Chan types that can be written to. A minimum complete--- instance defines one of 'writeList2Chan' or 'writeChan'-class WritableChan c where+-- | A class for chan types with a \"write end\" and a \"read end\". A minimal+-- complete instance defines 'readChan' and one of 'writeChan' or+-- 'writeList2Chan'.+class SplitChan i o | i -> o, o -> i where+    -- | Read the next value from the 'OutChan'.+    readChan :: o a -> IO a+     -- | Write an entire list of items to a chan type-    writeList2Chan :: c a -> [a] -> IO ()+    writeList2Chan :: i a -> [a] -> IO ()     writeList2Chan = mapM_ . writeChan      -- | Write a value to a Chan type.-    writeChan :: c a -> a -> IO ()+    writeChan :: i a -> a -> IO ()     writeChan c = writeList2Chan c . return --- | A class for Chan types that can be read from. -class ReadableChan c where-    -- | Read the next value from the 'OutChan'.-    readChan :: c a -> IO a-+-- | A class for 'SplitChan' types that can be instantiated without programmer+-- input. /e.g./ the standard haskell @Chan@ is a member of this class, however+-- a bounded chan type that took an @Int@ to define the buffer size would not.+class (SplitChan i o)=> NewSplitChan i o where+    newSplitChan :: IO (i a, o a)   -- -------------------------------@@ -36,17 +41,20 @@ -- -------------------------------  -instance WritableChan C.Chan where+instance SplitChan C.Chan C.Chan where     writeList2Chan = C.writeList2Chan     writeChan = C.writeChan--instance ReadableChan C.Chan where     readChan = C.readChan +instance NewSplitChan C.Chan C.Chan where+    newSplitChan = do c <- C.newChan+                      return (c,c) --- an MVar is a bounded Singleton Chan. Think about it.-instance WritableChan MVar where+-- an MVar is a singly-bounded Chan. Think about it.+instance SplitChan MVar MVar where     writeChan = putMVar--instance ReadableChan MVar where     readChan = takeMVar+       +instance NewSplitChan MVar MVar where+    newSplitChan = do v <- newEmptyMVar+                      return (v,v)
Control/Concurrent/Chan/Split.hs view
@@ -1,8 +1,7 @@-{-# LANGUAGE GADTs #-}+{-# LANGUAGE GADTs, MultiParamTypeClasses #-} module Control.Concurrent.Chan.Split (     -- * Chan pairs-      newSplitChan-    , InChan()+      InChan()     , OutChan()     -- * Utility functions:     , getChanContents@@ -16,9 +15,10 @@ import Data.Cofunctor import Control.Applicative import Control.Arrow--- provided by chan-split: import Control.Concurrent.Chan.Class ++ -- 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@@ -32,18 +32,15 @@ data OutChan o where     OutChan :: (a -> o) -> C.Chan a -> OutChan o --- | Create corresponding read and write ends of a chan pair. Writes to the--- 'InChan' side can be read on the 'OutChan' side.-newSplitChan :: IO (InChan a, OutChan a)-newSplitChan = (InChan id &&& OutChan id) <$> C.newChan-+instance NewSplitChan InChan OutChan where+    -- | Create corresponding read and write ends of a chan pair. Writes to the+    -- 'InChan' side can be read on the 'OutChan' side.+    newSplitChan = (InChan id &&& OutChan id) <$> C.newChan  -instance WritableChan InChan where+instance SplitChan InChan OutChan where     writeChan (InChan f c) = C.writeChan c . f     writeList2Chan (InChan f c) = C.writeList2Chan c . map f--instance ReadableChan OutChan where     readChan (OutChan f c) = f <$> C.readChan c   instance Cofunctor InChan where@@ -74,5 +71,5 @@ mergeOutChans cs =      as <- mapM C.getChanContents cs     ...-    -}+-} 
− Data/Cofunctor.lhs
@@ -1,10 +0,0 @@-> module Data.Cofunctor (->     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
chan-split.cabal view
@@ -8,7 +8,7 @@ -- 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.3+Version:             0.2.0  -- A short (one-line) description of the package. Synopsis:            Concurrent Chans as read/write pairs. Also provides generic@@ -41,8 +41,22 @@                      Note, we do not implement the deprecated unGetChan and                       isEmptyChan functions.                      .-                     This module is used internally by the simple-actors package.+                     This module is used internally by the "simple-actors" package.+                     .+                     /CHANGES/:+                     0.1.3 -> 0.2.0   +                        - moved @Data.Cofunctor@ to its own module "cofunctor"++                        - redefine chan pair classes using fundeps+                          to express the relationship between input+                          and output halfs of a Chan++                        - define 'NewSplitChan' class for chan pairs that can be+                          instantiated+                     . ++ -- The license under which the package is released. License:             BSD3 @@ -76,13 +90,17 @@   Library-  -- Modules exported by the library.+                     -- for the split chan class:+  Extensions:          MultiParamTypeClasses+                     , FunctionalDependencies +                     -- for Functor / Cofunctor instances:+                     , GADTs+   Exposed-modules:     Control.Concurrent.Chan.Split                      , Control.Concurrent.Chan.Class-                     , Data.Cofunctor   -  -- Packages needed in order to build this package.   Build-depends:       base >= 4 && < 5+                     , cofunctor      ghc-options:        -Wall