Cabal-3.12.1.0: A framework for packaging Haskell software

Copyright | Isaac Jones 2003-2004 Duncan Coutts 2007
License | BSD3
Maintainer | cabal-devel@haskell.org
Portability | portable
Safe Haskell | Safe-Inferred
Language | Haskell2010

Distribution.Simple.Flag

Description

Defines the `Flag` type and it's `Monoid` instance, see http://www.haskell.org/pipermail/cabal-devel/2007-December/001509.html for an explanation.

Split off from Distribution.Simple.Setup to break import cycles.

Synopsis

- data Flag a
  - = Flag a
  - | NoFlag
- allFlags :: [Flag Bool] -> Flag Bool
- toFlag :: a -> Flag a
- fromFlag :: WithCallStack (Flag a -> a)
- fromFlagOrDefault :: a -> Flag a -> a
- flagElim :: b -> (a -> b) -> Flag a -> b
- flagToMaybe :: Flag a -> Maybe a
- flagToList :: Flag a -> [a]
- maybeToFlag :: Maybe a -> Flag a
- mergeListFlag :: Flag [a] -> Flag [a] -> Flag [a]
- class BooleanFlag a where
  - asBool :: a -> Bool

# Documentation

data Flag a Source #

All flags are monoids, they come in two flavours:

1. list flags eg

    --ghc-option=foo --ghc-option=bar

gives us all the values ["foo", "bar"]

1. singular value flags, eg:

    --enable-foo --disable-foo

gives us Just False

So, this `Flag` type is for the latter singular kind of flag. Its monoid instance gives us the behaviour where it starts out as `NoFlag` and later flags override earlier ones.

Isomorphic to `Maybe` a.

Constructors

Flag a |
NoFlag |

#### Instances

Instances details

Applicative Flag Source # |
Instance details Defined in Distribution.Simple.Flag Methods pure :: a -> Flag a # (<*>) :: Flag (a -> b) -> Flag a -> Flag b # liftA2 :: (a -> b -> c) -> Flag a -> Flag b -> Flag c # (*>) :: Flag a -> Flag b -> Flag b # (<*) :: Flag a -> Flag b -> Flag a #
Functor Flag Source # |
Instance details Defined in Distribution.Simple.Flag Methods fmap :: (a -> b) -> Flag a -> Flag b # (<$) :: a -> Flag b -> Flag a #
Foldable Flag Source # |

Instance details

Defined in Distribution.Simple.Flag

Methods

fold :: Monoid m => Flag m -> m #

foldMap :: Monoid m => (a -> m) -> Flag a -> m #

foldMap' :: Monoid m => (a -> m) -> Flag a -> m #

foldr :: (a -> b -> b) -> b -> Flag a -> b #

foldr' :: (a -> b -> b) -> b -> Flag a -> b #

foldl :: (b -> a -> b) -> b -> Flag a -> b #

foldl' :: (b -> a -> b) -> b -> Flag a -> b #

foldr1 :: (a -> a -> a) -> Flag a -> a #

foldl1 :: (a -> a -> a) -> Flag a -> a #

toList :: Flag a -> [a] #

null :: Flag a -> Bool #

length :: Flag a -> Int #

elem :: Eq a => a -> Flag a -> Bool #

maximum :: Ord a => Flag a -> a #

minimum :: Ord a => Flag a -> a #

sum :: Num a => Flag a -> a #

product :: Num a => Flag a -> a #

Traversable Flag Source # |
Instance details Defined in Distribution.Simple.Flag Methods traverse :: Applicative f => (a -> f b) -> Flag a -> f (Flag b) # sequenceA :: Applicative f => Flag (f a) -> f (Flag a) # mapM :: Monad m => (a -> m b) -> Flag a -> m (Flag b) # sequence :: Monad m => Flag (m a) -> m (Flag a) #
Structured a => Structured (Flag a) Source # |
Instance details Defined in Distribution.Simple.Flag Methods structure :: Proxy (Flag a) -> Structure Source # structureHash' :: Tagged (Flag a) MD5
Binary a => Binary (Flag a) Source # |
Instance details Defined in Distribution.Simple.Flag Methods put :: Flag a -> Put # get :: Get (Flag a) # putList :: [Flag a] -> Put #
Monoid (Flag a) Source # |
Instance details Defined in Distribution.Simple.Flag Methods mempty :: Flag a # mappend :: Flag a -> Flag a -> Flag a # mconcat :: [Flag a] -> Flag a #
Semigroup (Flag a) Source # |
Instance details Defined in Distribution.Simple.Flag Methods (<>) :: Flag a -> Flag a -> Flag a # sconcat :: NonEmpty (Flag a) -> Flag a # stimes :: Integral b => b -> Flag a -> Flag a #
Bounded a => Bounded (Flag a) Source # |
Instance details Defined in Distribution.Simple.Flag Methods minBound :: Flag a # maxBound :: Flag a #
Enum a => Enum (Flag a) Source # |
Instance details Defined in Distribution.Simple.Flag Methods succ :: Flag a -> Flag a # pred :: Flag a -> Flag a # toEnum :: Int -> Flag a # fromEnum :: Flag a -> Int # enumFrom :: Flag a -> [Flag a] # enumFromThen :: Flag a -> Flag a -> [Flag a] # enumFromTo :: Flag a -> Flag a -> [Flag a] # enumFromThenTo :: Flag a -> Flag a -> Flag a -> [Flag a] #
Generic (Flag a) Source # |

Instance details

Defined in Distribution.Simple.Flag

Associated Types

type Rep (Flag a) |
Instance details Defined in Distribution.Simple.Flag type Rep (Flag a) = D1 ('MetaData "Flag" "Distribution.Simple.Flag" "Cabal-3.12.1.0-cda0" 'False) (C1 ('MetaCons "Flag" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)) :+: C1 ('MetaCons "NoFlag" 'PrefixI 'False) (U1 :: Type -> Type))

Methods

from :: Flag a -> Rep (Flag a) x #

to :: Rep (Flag a) x -> Flag a #

Read a => Read (Flag a) Source # |
Instance details Defined in Distribution.Simple.Flag Methods readsPrec :: Int -> ReadS (Flag a) # readList :: ReadS [Flag a] # readPrec :: ReadPrec (Flag a) # readListPrec :: ReadPrec [Flag a] #
Show a => Show (Flag a) Source # |
Instance details Defined in Distribution.Simple.Flag Methods showsPrec :: Int -> Flag a -> ShowS # show :: Flag a -> String # showList :: [Flag a] -> ShowS #
Eq a => Eq (Flag a) Source # |
Instance details Defined in Distribution.Simple.Flag Methods (==) :: Flag a -> Flag a -> Bool # (/=) :: Flag a -> Flag a -> Bool #
type Rep (Flag a) Source # |
Instance details Defined in Distribution.Simple.Flag type Rep (Flag a) = D1 ('MetaData "Flag" "Distribution.Simple.Flag" "Cabal-3.12.1.0-cda0" 'False) (C1 ('MetaCons "Flag" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)) :+: C1 ('MetaCons "NoFlag" 'PrefixI 'False) (U1 :: Type -> Type))

allFlags :: [Flag Bool] -> Flag Bool Source #

Returns `True` only if every `Flag` `Bool` value is Flag True, else `False`.

toFlag :: a -> Flag a Source #

Wraps a value in `Flag`.

fromFlag :: WithCallStack (Flag a -> a) Source #

Extracts a value from a `Flag`, and throws an exception on `NoFlag`.

fromFlagOrDefault :: a -> Flag a -> a Source #

Extracts a value from a `Flag`, and returns the default value on `NoFlag`.

flagElim :: b -> (a -> b) -> Flag a -> b Source #

Pushes a function through a `Flag` value, and returns a default if the `Flag` value is `NoFlag`.

Since: Cabal-3.4.0.0

flagToMaybe :: Flag a -> Maybe a Source #

Converts a `Flag` value to a `Maybe` value.

flagToList :: Flag a -> [a] Source #

Converts a `Flag` value to a list.

maybeToFlag :: Maybe a -> Flag a Source #

Converts a `Maybe` value to a `Flag` value.

mergeListFlag :: Flag [a] -> Flag [a] -> Flag [a] Source #

Merge the elements of a list `Flag` with another list `Flag`.

class BooleanFlag a where Source #

Types that represent boolean flags.

Methods

asBool :: a -> Bool Source #

#### Instances

Instances details

BooleanFlag Bool Source # |
Instance details Defined in Distribution.Simple.Flag Methods asBool :: Bool -> Bool Source #