This module provides type classes for working with sets of flags. In particular, with wrappers around bit masks:
import Data.Flags newtype MyFlags = MyFlags CInt deriving (Eq, Flags) #{enum MyFlags, MyFlags , myFlag1 = C_FLAG1 , myFlag2 = C_FLAG2 , myFlag3 = C_FLAG3 } f :: MyFlags -> IO () f = ...
Or, using Template Haskell:
import Data.Flags.TH $(bitmaskWrapper "MyFlags" ''CInt [] False [("myFlag1", #{const C_FLAG1}), ("myFlag2", #{const C_FLAG2}), ("myFlag3", #{const C_FLAG3})])
And then use it like this:
f $ myFlag1 .+. myFlag3
- class Eq a => Flags a where
- noFlags :: a
- andFlags :: a -> a -> a
- butFlags :: a -> a -> a
- commonFlags :: a -> a -> a
- (.+.) :: Flags a => a -> a -> a
- (.-.) :: Flags a => a -> a -> a
- (.*.) :: Flags a => a -> a -> a
- class Flags a => BoundedFlags a where
- allBut :: BoundedFlags a => a -> a
- containsAll :: Flags a => a -> a -> Bool
- (.<=.) :: Flags a => a -> a -> Bool
- (.>=.) :: Flags a => a -> a -> Bool
- containsSome :: Flags a => a -> a -> Bool
- (.~.) :: Flags a => a -> a -> Bool
- containsNone :: Flags a => a -> a -> Bool
- (./~.) :: Flags a => a -> a -> Bool
Documentation
class Eq a => Flags a whereSource
The empty set of flags.
Union of two flag sets.
Difference between two flag sets.
commonFlags :: a -> a -> aSource
Intersection of two flag sets.
(.*.) :: Flags a => a -> a -> aSource
Alias for commonFlags
.
class Flags a => BoundedFlags a whereSource
Use this class when the set of flags is fixed and not likely to change in the future.
allBut :: BoundedFlags a => a -> aSource
containsAll :: Flags a => a -> a -> BoolSource
Test if the first flag set contains all flags from the second.
(.>=.) :: Flags a => a -> a -> BoolSource
Alias for containsAll
.
containsSome :: Flags a => a -> a -> BoolSource
Test if two flag sets intersect.
(.~.) :: Flags a => a -> a -> BoolSource
Alias for containsSome
.
containsNone :: Flags a => a -> a -> BoolSource
Test if two flag sets do not intersect.
(./~.) :: Flags a => a -> a -> BoolSource
Alias for containsNone
.