packages feed

set-monad

Set monad

view on Hackage

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@, @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 will also get the aforementioned instances which are not available in the @containers@ package. It is not possible to directly implement instances for the aforementioned standard Haskell type classes for the @Set@ data type from the @containers@ library. This is because the key operations @map@ and @union@, are constrained with @Ord@ as follows. > map :: (Ord a, Ord b) => (a -> b) -> Set a -> Set b > union :: (Ord a) => Set a -> Set a -> Set a The @set-monad@ library provides the type class instances by wrapping the constrained @Set@ type into a data type that has unconstrained constructors corresponding to monadic combinators. The data type constructors that represent monadic combinators are evaluated with a constrained run function. This elevates the need to use the constraints in the instance definitions (this is what prevents a direct definition). The wrapping and unwrapping happens internally in the library and does not affect its interface. For details, see the rather compact definitions of the @run@ function and type class instances. The left identity and associativity monad laws play a crucial role in the definition of the @run@ function. The rest of the code should be self explanatory. The technique is not new. This library was inspired by [1]. To my knowledge, the original, systematic presentation of the idea to represent monadic combinators as data is given in [2]. There is also a Haskell library that provides a generic infrastructure for the aforementioned wrapping and unwrapping [3]. The @set-monad@ library is particularly useful for writing set-oriented code using the do and/or monad comprehension notations. For example, the following definitions now type check. > s1 :: Set (Int,Int) > s1 = do a <- fromList [1 .. 4] > b <- fromList [1 .. 4] > return (a,b) > -- with -XMonadComprehensions > s2 :: Set (Int,Int) > s2 = [ (a,b) | (a,b) <- s1, even a, even b ] > s3 :: Set Int > s3 = fmap (+1) (fromList [1 .. 4]) As noted in [1], the implementation technique can be used for monadic libraries and EDSLs with restricted types (compiled EDSLs often restrict the types that they can handle). Haskell's standard monad type class can be used for restricted monad instances. There is no need to resort to GHC extensions that rebind the standard monadic combinators with the library or EDSL specific ones. @[@1@]@ CSDL Blog: The home of applied functional programming at KU. Monad Reification in Haskell and the Sunroof Javascript compiler. <http://www.ittc.ku.edu/csdlblog/?p=88> @[@2@]@ Chuan-kai Lin. 2006. Programming monads operationally with Unimo. In Proceedings of the eleventh ACM SIGPLAN International Conference on Functional Programming (ICFP '06). ACM. @[@3@]@ Heinrich Apfelmus. The operational package. <http://hackage.haskell.org/package/operational>
versionuploadeduploaderchanges
0.3.0.02018-10-11 09:48 UTCGeorgeGiorgidze1 revisions+6/−4 lines, 2 filesdep ~basePVP ok
0.2.0.02015-01-04 01:11 UTCGeorgeGiorgidze1 revisions+33/−14 lines, 2 filesPVP ok
0.1.0.02012-06-16 00:24 UTCGeorgeGiorgidze1 revisions+475/−0 lines, 4 filesdep +basedep +containersdep +deepseqsetup-changed

Dependencies of set-monad-0.3.0.0

base >=4.11 && <5 4.22.0.0 → 4.22.1.0
2026-12-01 12:38 UTC4.22.1.0+388/−6 lines, 9 filesdep ~ghc-internalPVP: major bump suggested
2025-12-19 11:52 UTC4.22.0.0+886/−215 lines, 28 filesdep ~ghc-internalPVP ok
2026-03-27 12:26 UTC4.21.2.0+10/−3 lines, 4 filesdep ~ghc-internalPVP ok
2025-12-27 10:31 UTC4.21.1.0+17/−5 lines, 4 filesdep ~ghc-internalPVP ok
2024-12-16 09:24 UTC4.21.0.0+1170/−396 lines, 39 filesdep ~ghc-internalPVP ok

showing 5 of 61 versions

containers >=0 0.8 → 0.8.1
2026-10-04 06:08 UTC0.8.1+8085/−5169 lines, 39 filesdep +template-haskell-liftdep ~arraydep ~deepseqPVP: major bump suggested
2025-03-01 13:03 UTC0.8+8447/−7031 lines, 37 filesnew-uploaderPVP ok
2023-09-27 12:15 UTC0.7+76/−33 lines, 3 filesPVP ok
2023-09-28 04:21 UTC0.6.8+644/−184 lines, 17 filesdep ~basedep ~deepseqPVP: major bump suggested
2023-02-01 03:11 UTC0.6.7+783/−229 lines, 20 filesPVP: major bump suggested

showing 5 of 43 versions

deepseq >=0 1.5.2.0 → 1.6.0.0
2024-09-08 16:18 UTC1.6.0.0+5/−14 lines, 3 filesdep ~basePVP ok
2025-06-14 22:25 UTC1.5.2.0+13/−4 lines, 3 filesPVP: major bump suggested
2024-09-09 12:48 UTC1.5.1.0+69/−14 lines, 3 filesdep −arraydep ~basePVP: major bump suggested
2023-07-27 19:32 UTC1.5.0.0+619/−532 lines, 5 filesdep ~basePVP ok
2022-12-18 00:14 UTC1.4.8.1+34/−9 lines, 3 filesdep ~basePVP: major bump suggested

showing 5 of 26 versions

Reverse dependencies

1 packages depend on set-monad

dsh-sql 0.2.0.2 requires set-monad >=0.1