Safe Haskell | Safe-Inferred |
---|---|

Language | Haskell2010 |

# Introduction

This module provides a data type for a set of flags. Flags are stored efficiently as bits of an unsigned integer.

This module is meant to be imported qualified:

import qualified Data.FlagSet as FlagSet import Data.FlagSet (FlagSet)

The API is basically the same as that of Data.Set from the `containers`

package.

The functions `fromList`

and `member`

also have aliases that can be used
unqualified:

import Data.FlagSet (flags, hasFlag)

# Examples

import qualified Data.FlagSet as FlagSet import Data.FlagSet (FlagSet, flags, hasFlag) data WeekDay = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday deriving (Eq, Show, Enum, Bounded) workDays = flags [Monday .. Friday] weekEndDays = flags [Saturday, Sunday] allDays = FlagSet.full worksOnTheWeekEnd :: FlagSet WeekDay -> Bool worksOnTheWeekEnd = not . FlagSet.null . FlagSet.intersection weekEndDays worksOnSunday :: FlagSet WeekDay -> Bool worksOnSunday = hasFlag Sunday workDayPay :: Rational workDayPay = ... weekEndDayPay :: Rational weekEndDayPay = ... pay :: FlagSet WeekDay -> Rational pay daysWorking = workDayPay * countDays workDays + weekEndDayPay * countDays weekEndDays where countDays = fromIntegral . FlagSet.size . FlagSet.intersection daysWorking

- data FlagSet a
- fromList :: Enum a => [a] -> FlagSet a
- flags :: Enum a => [a] -> FlagSet a
- empty :: FlagSet a
- singleton :: Enum a => a -> FlagSet a
- full :: (Enum a, Bounded a) => FlagSet a
- insert :: Enum a => a -> FlagSet a -> FlagSet a
- delete :: Enum a => a -> FlagSet a -> FlagSet a
- union :: FlagSet a -> FlagSet a -> FlagSet a
- unions :: [FlagSet a] -> FlagSet a
- difference :: FlagSet a -> FlagSet a -> FlagSet a
- intersection :: FlagSet a -> FlagSet a -> FlagSet a
- member :: Enum a => a -> FlagSet a -> Bool
- hasFlag :: Enum a => a -> FlagSet a -> Bool
- null :: FlagSet a -> Bool
- toList :: Enum a => FlagSet a -> [a]
- size :: FlagSet a -> Int

# Types

# Construction

fromList :: Enum a => [a] -> FlagSet a Source

Create a flag set from a list of flags. Input list can contain duplicates.

# Modification

difference :: FlagSet a -> FlagSet a -> FlagSet a Source

The difference of two flag sets.

intersection :: FlagSet a -> FlagSet a -> FlagSet a Source

The intersection of two flag sets.

# Tests

hasFlag :: Enum a => a -> FlagSet a -> Bool Source

Alias for `member`

that can be imported unqualified.