Safe Haskell | None |
---|---|
Language | Haskell2010 |
Variation
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 = (<>)
Variation | |
|
(Bind f, Monoid1 f) => Monad (Variation f) Source # | |
Functor f => Functor (Variation f) Source # | |
(Apply f, Monoid1 f) => Applicative (Variation f) Source # | |
Foldable f => Foldable (Variation f) Source # | |
Traversable f => Traversable (Variation f) Source # | |
Show1 f => Show1 (Variation f) Source # | |
Append1 f => Append1 (Variation f) Source # | |
(Show1 f, Show a) => Show (Variation f a) Source # | |
Generic (Variation f a) Source # | |
Append1 f => Semigroup (Variation f a) Source # | |
(Monoid a, Monoid1 f) => Monoid (Variation f a) Source # | |
(Serialize a, Serialize (f a)) => Serialize (Variation f a) Source # | |
(NFData a, NFData (f a)) => NFData (Variation f a) Source # | |
type Rep (Variation f a) Source # | |