set-monad 0.1.0.0 → 0.2.0.0
raw patch · 2 files changed
+33/−14 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Set.Monad: instance [safe] Foldable Set
Files
- Data/Set/Monad.hs +31/−12
- set-monad.cabal +2/−2
Data/Set/Monad.hs view
@@ -156,8 +156,10 @@ import qualified Data.Set as S import qualified Data.Functor as F import qualified Control.Applicative as A+import qualified Data.Foldable as Foldable import Data.Monoid+import Data.Foldable (Foldable) import Control.Arrow import Control.Monad import Control.DeepSeq@@ -170,15 +172,22 @@ Plus :: Set a -> Set a -> Set a run :: (Ord a) => Set a -> S.Set a-run (Prim s) = s-run (Return a) = S.singleton a-run (Zero) = S.empty-run (Plus ma mb) = S.union (run ma) (run mb)-run (Bind (Prim s) f) = S.foldl' S.union S.empty (S.map (run . f) s)-run (Bind (Return a) f) = run (f a)-run (Bind Zero _) = S.empty-run (Bind (Plus ma mb) f) = run (Plus (Bind ma f) (Bind mb f))-run (Bind (Bind m f) g) = run (Bind m (\a -> Bind (f a) g))+run (Prim s) = s+run (Return a) = S.singleton a+run (Zero) = S.empty+run (Plus ma mb) = run ma `S.union` run mb+run (Bind (Prim s) f) = S.foldl' S.union S.empty (S.map (run . f) s)+run (Bind (Return a) f) = run (f a)+run (Bind Zero _) = S.empty+run (Bind (Plus (Prim s) ma) f) = run (Bind (Prim (s `S.union` run ma)) f)+run (Bind (Plus ma (Prim s)) f) = run (Bind (Prim (run ma `S.union` s)) f)+run (Bind (Plus (Return a) ma) f) = run (Plus (f a) (Bind ma f))+run (Bind (Plus ma (Return a)) f) = run (Plus (Bind ma f) (f a))+run (Bind (Plus Zero ma) f) = run (Bind ma f)+run (Bind (Plus ma Zero) f) = run (Bind ma f)+run (Bind (Plus (Plus ma mb) mc) f) = run (Bind (Plus ma (Plus mb mc)) f)+run (Bind (Plus ma mb) f) = run (Plus (Bind ma f) (Bind mb f))+run (Bind (Bind ma f) g) = run (Bind ma (\a -> Bind (f a) g)) instance F.Functor Set where fmap = liftM@@ -188,8 +197,8 @@ (<*>) = ap instance A.Alternative Set where- empty = mzero- (<|>) = mplus+ empty = Zero+ (<|>) = Plus instance Monad Set where return = Return@@ -204,6 +213,16 @@ mappend = union mconcat = unions +instance Foldable Set where+ foldr f def m = + case m of+ Prim s -> S.foldr f def s+ Return a -> f a def+ Zero -> def+ Plus ma mb -> Foldable.foldr f (Foldable.foldr f def ma) mb+ Bind s g -> Foldable.foldr f' def s+ where f' x b = Foldable.foldr f b (g x)+ instance (Ord a) => Eq (Set a) where s1 == s2 = run s1 == run s2 @@ -255,7 +274,7 @@ delete a s = Prim (S.delete a (run s)) union :: (Ord a) => Set a -> Set a -> Set a-union s1 s2 = Prim (S.union (run s1) (run s2))+union s1 s2 = Prim (run s1 `S.union` run s2) unions :: (Ord a) => [Set a] -> Set a unions ss = Prim (S.unions (L.map run ss))
set-monad.cabal view
@@ -1,12 +1,12 @@ name: set-monad-version: 0.1.0.0+version: 0.2.0.0 synopsis: Set monad description: The @set-monad@ library exports the @Set@ abstract data type and set-manipulating functions. These functions behave exactly as their namesakes from the @Data.Set@ module of the @containers@ library. In addition, the @set-monad@ library extends @Data.Set@ by providing @Functor@, @Applicative@,- @Alternative@, @Monad@, and @MonadPlus@ instances for sets.+ @Alternative@, @Foldable@, @Monad@, and @MonadPlus@ instances for sets. . In other words, you can use the @set-monad@ library as a drop-in replacement for the @Data.Set@ module of the @containers@ library and, in addition, you