| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
Data.ProtocolBuffers.Orphans
Description
Messages containing Optional Enumeration fields fail to encode.
This module contains orphan instances required to make these functional.
For more information reference the associated ticket: https://github.com/alphaHeavy/protobuf/issues/3
- class Foldable t
Documentation
class Foldable t
Data structures that can be folded.
For example, given a data type
data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a)
a suitable instance would be
instance Foldable Tree where foldMap f Empty = mempty foldMap f (Leaf x) = f x foldMap f (Node l k r) = foldMap f l `mappend` f k `mappend` foldMap f r
This is suitable even for abstract types, as the monoid is assumed
to satisfy the monoid laws. Alternatively, one could define foldr:
instance Foldable Tree where foldr f z Empty = z foldr f z (Leaf x) = f x z foldr f z (Node l k r) = foldr f (f k (foldr f z r)) l
Foldable instances are expected to satisfy the following laws:
foldr f z t = appEndo (foldMap (Endo . f) t ) z
foldl f z t = appEndo (getDual (foldMap (Dual . Endo . flip f) t)) z
fold = foldMap id
sum, product, maximum, and minimum should all be essentially
equivalent to foldMap forms, such as
sum = getSum . foldMap Sum
but may be less defined.
If the type is also a Functor instance, it should satisfy
foldMap f = fold . fmap f
which implies that
foldMap f . fmap g = foldMap (f . g)
Instances
| Foldable [] | |
| Foldable Identity | |
| Foldable Maybe | |
| Foldable Digit | |
| Foldable Node | |
| Foldable Elem | |
| Foldable FingerTree | |
| Foldable IntMap | |
| Foldable Set | |
| Foldable Seq | |
| Foldable ViewL | |
| Foldable ViewR | |
| Foldable Fixed | |
| Foldable Signed | |
| Foldable PackedList | |
| Foldable PackedField | |
| Foldable Enumeration | |
| Foldable Always | |
| Foldable RepeatedField | |
| Foldable OptionalField | |
| Foldable RequiredField | |
| Foldable Value | |
| Foldable Message | |
| Foldable (Either a) | |
| Foldable ((,) a) | |
| Ix i => Foldable (Array i) | |
| Foldable (Const m) | |
| Foldable (Proxy *) | |
| Foldable (Map k) | |
| Foldable (HashMap k) | |
| Foldable (Field n) |