**diff options**

Diffstat (limited to 'src/Voting/Protocol/Utils.hs')

-rw-r--r-- | src/Voting/Protocol/Utils.hs | 31 |

1 files changed, 14 insertions, 17 deletions

diff --git a/src/Voting/Protocol/Utils.hs b/src/Voting/Protocol/Utils.hs index ea1fbb9..1cc30f0 100644 --- a/src/Voting/Protocol/Utils.hs +++ b/src/Voting/Protocol/Utils.hs @@ -10,6 +10,12 @@ import Data.Maybe (Maybe(..), maybe) import Data.Traversable (Traversable(..)) import qualified Data.List as List +-- | Like ('.') but with two arguments. +o2 :: (c -> d) -> (a -> b -> c) -> a -> b -> d +o2 f g = \x y -> f (g x y) +infixr 9 `o2` +{-# INLINE o2 #-} + -- | NOTE: check the lengths before applying @f@. isoZipWith :: (a->b->c) -> [a]->[b]->Maybe [c] isoZipWith f as bs @@ -25,38 +31,29 @@ isoZipWith3 f as bs cs where al = List.length as isoZipWithM :: - Applicative m => - m () -> - (a -> b -> m c) -> - [a] -> [b] -> m [c] + Applicative f => + f () -> (a->b->f c) -> [a]->[b]->f [c] isoZipWithM err f as bs = maybe ([] <$ err) sequenceA $ isoZipWith f as bs isoZipWithM_ :: - Applicative m => - m () -> - (a -> b -> m c) -> - [a] -> [b] -> m () + Applicative f => + f () -> (a->b->f c) -> [a]->[b]->f () isoZipWithM_ err f as bs = maybe err sequenceA_ $ isoZipWith f as bs isoZipWith3M :: - Applicative m => - m () -> - (a -> b -> c -> m d) -> - [a] -> [b] -> [c] -> m [d] + Applicative f => + f () -> (a->b->c->f d) -> [a]->[b]->[c]->f [d] isoZipWith3M err f as bs cs = maybe ([] <$ err) sequenceA $ isoZipWith3 f as bs cs isoZipWith3M_ :: - Applicative m => - m () -> - (a -> b -> c -> m d) -> - [a] -> [b] -> [c] -> - m () + Applicative f => + f () -> (a->b->c->f d) -> [a]->[b]->[c]->f () isoZipWith3M_ err f as bs cs = maybe err sequenceA_ $ isoZipWith3 f as bs cs |