variation-0.1.1.0: nominal value with possible variations

Safe HaskellNone
LanguageHaskell2010

Data.Variation

Contents

Synopsis

Variation

data Variation f a Source #

the variation type contains

_nominal
: a nominal value that will always exist
_variations
: alternative values which are held inside a container of type f

it is strict in both arguments.

the Applicative instance uses the Unit1 instance of f to define pure

pure x = Variation x empty1

and the Bind and Append1 instances of f to define <*>

Variation f fs <*> Variation x xs =
  Variation
    (f x)
    ((fs <.> xs) `append1` (f <$> xs) `append1` (($ x) <$> fs))

the Monad instance uses the Bind instance of f (join) to collapse collections of type f (f a)

joinV :: (Bind f, Monoid1 f) => Variation f (Variation f a) -> Variation f a
joinV (Variation (Variation nn nv) v) =
  let vv = _variations <$> v
      vn = _nominal <$> v
  in Variation nn $ join vv `append1` vn `append1` nv

other useful instances:

instance Append1 f => Semigroup (Variation f a) where
  (<>) = append1
instance (Monoid a, Monoid1 f) => Monoid (Variation f a) where
  mempty = Variation mempty empty1
  mappend = (<>)

Constructors

Variation 

Fields

Instances

(Bind f, Monoid1 f) => Monad (Variation f) Source # 

Methods

(>>=) :: Variation f a -> (a -> Variation f b) -> Variation f b #

(>>) :: Variation f a -> Variation f b -> Variation f b #

return :: a -> Variation f a #

fail :: String -> Variation f a #

Functor f => Functor (Variation f) Source # 

Methods

fmap :: (a -> b) -> Variation f a -> Variation f b #

(<$) :: a -> Variation f b -> Variation f a #

(Apply f, Monoid1 f) => Applicative (Variation f) Source # 

Methods

pure :: a -> Variation f a #

(<*>) :: Variation f (a -> b) -> Variation f a -> Variation f b #

(*>) :: Variation f a -> Variation f b -> Variation f b #

(<*) :: Variation f a -> Variation f b -> Variation f a #

Foldable f => Foldable (Variation f) Source # 

Methods

fold :: Monoid m => Variation f m -> m #

foldMap :: Monoid m => (a -> m) -> Variation f a -> m #

foldr :: (a -> b -> b) -> b -> Variation f a -> b #

foldr' :: (a -> b -> b) -> b -> Variation f a -> b #

foldl :: (b -> a -> b) -> b -> Variation f a -> b #

foldl' :: (b -> a -> b) -> b -> Variation f a -> b #

foldr1 :: (a -> a -> a) -> Variation f a -> a #

foldl1 :: (a -> a -> a) -> Variation f a -> a #

toList :: Variation f a -> [a] #

null :: Variation f a -> Bool #

length :: Variation f a -> Int #

elem :: Eq a => a -> Variation f a -> Bool #

maximum :: Ord a => Variation f a -> a #

minimum :: Ord a => Variation f a -> a #

sum :: Num a => Variation f a -> a #

product :: Num a => Variation f a -> a #

Traversable f => Traversable (Variation f) Source # 

Methods

traverse :: Applicative f => (a -> f b) -> Variation f a -> f (Variation f b) #

sequenceA :: Applicative f => Variation f (f a) -> f (Variation f a) #

mapM :: Monad m => (a -> m b) -> Variation f a -> m (Variation f b) #

sequence :: Monad m => Variation f (m a) -> m (Variation f a) #

Show1 f => Show1 (Variation f) Source # 

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Variation f a -> ShowS #

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Variation f a] -> ShowS #

Append1 f => Append1 (Variation f) Source # 

Methods

append1 :: Variation f a -> Variation f a -> Variation f a Source #

(Show1 f, Show a) => Show (Variation f a) Source # 

Methods

showsPrec :: Int -> Variation f a -> ShowS #

show :: Variation f a -> String #

showList :: [Variation f a] -> ShowS #

Generic (Variation f a) Source # 

Associated Types

type Rep (Variation f a) :: * -> * #

Methods

from :: Variation f a -> Rep (Variation f a) x #

to :: Rep (Variation f a) x -> Variation f a #

Append1 f => Semigroup (Variation f a) Source # 

Methods

(<>) :: Variation f a -> Variation f a -> Variation f a #

sconcat :: NonEmpty (Variation f a) -> Variation f a #

stimes :: Integral b => b -> Variation f a -> Variation f a #

(Monoid a, Monoid1 f) => Monoid (Variation f a) Source # 

Methods

mempty :: Variation f a #

mappend :: Variation f a -> Variation f a -> Variation f a #

mconcat :: [Variation f a] -> Variation f a #

(Serialize a, Serialize (f a)) => Serialize (Variation f a) Source # 

Methods

put :: Putter (Variation f a) #

get :: Get (Variation f a) #

(NFData a, NFData (f a)) => NFData (Variation f a) Source # 

Methods

rnf :: Variation f a -> () #

type Rep (Variation f a) Source # 
type Rep (Variation f a) = D1 (MetaData "Variation" "Data.Variation" "variation-0.1.1.0-LQFmCGwOHr1FHYkVMaNdtJ" False) (C1 (MetaCons "Variation" PrefixI True) ((:*:) (S1 (MetaSel (Just Symbol "_nominal") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 a)) (S1 (MetaSel (Just Symbol "_variations") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (f a)))))

Lenses

nominal :: Functor f => (a -> f a) -> Variation t a -> f (Variation t a) Source #

variations :: Functor f => (t a -> f (t a)) -> Variation t a -> f (Variation t a) Source #