-- Communicating Haskell Processes.-- Copyright (c) 2008, University of Kent.-- 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 the University of Kent nor the names of its-- 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.-- | A module with support for things that are enrollable (barriers and broadcast-- channels).moduleControl.Concurrent.CHP.Enroll(Enrolled,Enrollable(..),furtherEnroll,enrollPair,enrollList)whereimportControl.Concurrent.CHP.BaseclassEnrollablebzwhere-- | Enrolls on the given barrier, then executes the given function (passing-- it in the enrolled barrier) and when that function body finishes, resigns-- from the barrier and returns the result. If a poison or IO exception is thrown-- in the inside block, the barrier will be correctly resigned from, and-- the exception rethrown.---- Do not attempt to return the-- enrolled barrier out of the inner function and use it afterwards.enroll::bz->(Enrolledbz->CHPa)->CHPa-- | Resigns from a barrier, then executes the given action, and when the-- action finishes, re-enrolls on the barrier and continues. This function-- is designed for use from /inside/ the body of the 'enroll' function, to-- temporarily resign from a barrier, do some things, then re-enroll. Do-- not use the enrolled barrier inside the resign block. However, you may-- enroll on the barrier inside this, nesting enroll and resign blocks as-- much as you likeresign::Enrolledbz->CHPa->CHPa-- | Just like enroll, but starts with an already enrolled item. During the-- body, you are enrolled twice -- once from the original enrolled item (which-- is still valid in the body) and once from the new enrolled item passed to-- the inner function. Afterwards, you are enrolled once, on the original item-- you had.---- This function was added in version 1.3.2.furtherEnroll::Enrollablebz=>Enrolledbz->(Enrolledbz->CHPa)->CHPafurtherEnroll(Enrolledx)=enrollx-- | Like 'enroll' but enrolls on the given pair of barriersenrollPair::(Enrollablebp,Enrollableb'p')=>(bp,b'p')->((Enrolledbp,Enrolledb'p')->CHPa)->CHPaenrollPair(b0,b1)f=enrollb0$\eb0->enrollb1$\eb1->f(eb0,eb1)-- | Like 'enroll' but enrolls on the given list of barriersenrollList::Enrollablebp=>[bp]->([Enrolledbp]->CHPa)->CHPaenrollList[]f=f[]enrollList(b:bs)f=enrollb$\eb->enrollListbs$\ebs->f(eb:ebs)