concurrent-split (empty) → 0.0
raw patch · 6 files changed
+172/−0 lines, 6 filesdep +basesetup-changed
Dependencies added: base
Files
- LICENSE +31/−0
- Setup.lhs +3/−0
- concurrent-split.cabal +47/−0
- src/Control/Concurrent/Split/Chan.hs +37/−0
- src/Control/Concurrent/Split/Class.hs +17/−0
- src/Control/Concurrent/Split/MVar.hs +37/−0
+ LICENSE view
@@ -0,0 +1,31 @@+Copyright (c) 2012, Henning Thielemann++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.++ * The names of contributors may not 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.
+ Setup.lhs view
@@ -0,0 +1,3 @@+#! /usr/bin/env runhaskell+> import Distribution.Simple+> main = defaultMain
+ concurrent-split.cabal view
@@ -0,0 +1,47 @@+Name: concurrent-split+Version: 0.0+License: BSD3+License-File: LICENSE+Author: Henning Thielemann <haskell@henning-thielemann.de>+Maintainer: Henning Thielemann <haskell@henning-thielemann.de>+Category: Concurrent+Build-Type: Simple+Synopsis: MVars and Channels with distinguished input and output side+Description:+ MVars and Channels with distinguished input and output side.+ When threads communicate via an MVar or a Chan+ there are often clearly defined roles,+ which thread is the sender and which one is receiver.+ We provide wrappers around the standard concurrency communication channels+ that make the distinction clear and type safe.+ .+ For example, if a function has a parameter of type @TChan.In@+ then it is sure that it will only write to that channel.+ Additionally if the compiler warns about an unused @TChan.Out@+ that was created by @TChan.new@+ then you know that the receiver part of your communication is missing.+ .+ See also package @stm-split@ for transactional communication.+ This package follows the same idea as @chan-split@ but is strictly Haskell 98.+Tested-With: GHC==6.12.3, GHC==7.4.1+Cabal-Version: >=1.6+Build-Type: Simple+Source-Repository this+ Tag: 0.0+ Type: darcs+ Location: http://code.haskell.org/~thielema/concurrent-split/++Source-Repository head+ Type: darcs+ Location: http://code.haskell.org/~thielema/concurrent-split/++Library+ Build-Depends:+ base >=4 && <5++ GHC-Options: -Wall+ Hs-Source-Dirs: src+ Exposed-Modules:+ Control.Concurrent.Split.Class+ Control.Concurrent.Split.MVar+ Control.Concurrent.Split.Chan
+ src/Control/Concurrent/Split/Chan.hs view
@@ -0,0 +1,37 @@+module Control.Concurrent.Split.Chan (+ T,+ In,+ Out,+ new,+ read,+ write,+ ) where++import qualified Control.Concurrent.Split.Class as Split++import qualified Control.Concurrent.Chan as Chan++import Prelude (IO, return, )+++newtype T dir a = Cons (Chan.Chan a)++type In = T Split.In+type Out = T Split.Out+++instance Split.C T where+ new = new+ read = read+ write = write++new :: IO (In a, Out a)+new = do+ v <- Chan.newChan+ return (Cons v, Cons v)++read :: Out a -> IO a+read (Cons v) = Chan.readChan v++write :: In a -> a -> IO ()+write (Cons v) a = Chan.writeChan v a
+ src/Control/Concurrent/Split/Class.hs view
@@ -0,0 +1,17 @@+module Control.Concurrent.Split.Class (In, Out, C, new, read, write, ) where++import Prelude (IO, )++data In = In+data Out = Out++_dummyIn :: In+_dummyIn = In++_dummyOut :: Out+_dummyOut = Out++class C chan where+ new :: IO (chan In a, chan Out a)+ read :: chan Out a -> IO a+ write :: chan In a -> a -> IO ()
+ src/Control/Concurrent/Split/MVar.hs view
@@ -0,0 +1,37 @@+module Control.Concurrent.Split.MVar (+ T,+ In,+ Out,+ newEmpty,+ take,+ put,+ ) where++import qualified Control.Concurrent.Split.Class as Split++import qualified Control.Concurrent.MVar as MVar++import Prelude (IO, return, )+++newtype T dir a = Cons (MVar.MVar a)++type In = T Split.In+type Out = T Split.Out+++instance Split.C T where+ new = newEmpty+ read = take+ write = put++newEmpty :: IO (In a, Out a)+newEmpty = do+ v <- MVar.newEmptyMVar+ return (Cons v, Cons v)++take :: Out a -> IO a+take (Cons v) = MVar.takeMVar v++put :: In a -> a -> IO ()+put (Cons v) a = MVar.putMVar v a