git.iko.soy/distributed-process
on master help sign in
Merge pull request #242 from Shimuuar/match-functor

Add Functor instance for Match data type. Main use of that instance is to allow composition of Matches of different type receiveWait [ Left <$> (match :: Match a) , Right <$> (match :: Match b) ] It's not always convenient/possible to set types of Match right at construction time.

commitb55e77debe2c0529d8e815bf0c397f75eebc1273 authorFacundo Domínguez <facundominguez@gmail.com> dateThu 25 Jun 2015, 12:58 (11 years ago) parent13428ac81bcb23
2 files changed+4
src/Control/Distributed/Process/Internal/CQueue.hs+2 src/Control/Distributed/Process/Internal/Primitives.hs+2
src/Control/Distributed/Process/Internal/CQueue.hs+2
@@ -1,3 +1,4 @@
1+{-# LANGUAGE DeriveFunctor #-}
12{-# LANGUAGE BangPatterns #-}
23{-# LANGUAGE MagicHash, UnboxedTuples, PatternGuards, ScopedTypeVariables, RankNTypes #-}
34-- | Concurrent queue for single reader, single writer
@@ -77,6 +78,7 @@ data BlockSpec =
7778data MatchOn m a
7879 = MatchMsg (m -> Maybe a)
7980 | MatchChan (STM a)
81+ deriving (Functor)
8082
8183type MatchChunks m a = [Either [m -> Maybe a] [STM a]]
8284
src/Control/Distributed/Process/Internal/Primitives.hs+2
@@ -1,6 +1,7 @@
11{-# LANGUAGE CPP #-}
22{-# LANGUAGE RankNTypes #-}
33{-# LANGUAGE DeriveDataTypeable #-}
4+{-# LANGUAGE DeriveFunctor #-}
45{-# LANGUAGE ScopedTypeVariables #-}
56{-# LANGUAGE ExistentialQuantification #-}
67{-# LANGUAGE BangPatterns #-}
@@ -374,6 +375,7 @@ mergePortsRR = \ps -> do
374375
375376-- | Opaque type used in 'receiveWait' and 'receiveTimeout'
376377newtype Match b = Match { unMatch :: MatchOn Message (Process b) }
378+ deriving (Functor)
377379
378380-- | Test the matches in order against each message in the queue
379381receiveWait :: [Match b] -> Process b