Hoogle Search
Within LTS Haskell 24.31 (ghc-9.10.3)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
foldMap :: (Foldable t, Monoid m) => (a -> m) -> t a -> mcabal-install-solver Distribution.Solver.Compat.Prelude Map each element of the structure into a monoid, and combine the results with (<>). This fold is right-associative and lazy in the accumulator. For strict left-associative folds consider foldMap' instead.
Examples
Basic usage:>>> foldMap Sum [1, 3, 5] Sum {getSum = 9}>>> foldMap Product [1, 3, 5] Product {getProduct = 15}>>> foldMap (replicate 3) [1, 2, 3] [1,1,1,2,2,2,3,3,3]
When a Monoid's (<>) is lazy in its second argument, foldMap can return a result even from an unbounded structure. For example, lazy accumulation enables Data.ByteString.Builder to efficiently serialise large data structures and produce the output incrementally:>>> import qualified Data.ByteString.Lazy as L >>> import qualified Data.ByteString.Builder as B >>> let bld :: Int -> B.Builder; bld i = B.intDec i <> B.word8 0x20 >>> let lbs = B.toLazyByteString $ foldMap bld [0..] >>> L.take 64 lbs "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24"
gmappend :: (Generic a, GSemigroup (Rep a)) => a -> a -> acabal-install-solver Distribution.Solver.Compat.Prelude Generically generate a Semigroup (<>) operation for any type implementing Generic. This operation will append two values by point-wise appending their component fields. It is only defined for product types.
gmappend a (gmappend b c) = gmappend (gmappend a b) c
concatMap :: forall a (m :: Nat) b (n :: Nat) . (a -> Vec m b) -> Vec n a -> Vec (n * m) bclash-prelude Clash.Explicit.Prelude Map a function over all the elements of a vector and concatentate the resulting vectors.
>>> concatMap (replicate d3) (1:>2:>3:>Nil) 1 :> 1 :> 1 :> 2 :> 2 :> 2 :> 3 :> 3 :> 3 :> Nil
imap :: forall (n :: Nat) a b . KnownNat n => (Index n -> a -> b) -> Vec n a -> Vec n bclash-prelude Clash.Explicit.Prelude Apply a function of every element of a vector and its index.
>>> :t imap (+) (2 :> 2 :> 2 :> 2 :> Nil) imap (+) (2 :> 2 :> 2 :> 2 :> Nil) :: Vec 4 (Index 4) >>> imap (+) (2 :> 2 :> 2 :> 2 :> Nil) 2 :> 3 :> *** Exception: X: Clash.Sized.Index: result 4 is out of bounds: [0..3] ... >>> imap (\i a -> extend (bitCoerce i) + a) (2 :> 2 :> 2 :> 2 :> Nil) :: Vec 4 (Unsigned 8) 2 :> 3 :> 4 :> 5 :> Nil
"imap f xs" corresponds to the following circuit layout:-
clash-prelude Clash.Explicit.Prelude Apply a function to every element of a vector and the element's position (as an SNat value) in the vector.
>>> let rotateMatrix = smap (flip rotateRightS) >>> let xss = (1:>2:>3:>Nil):>(1:>2:>3:>Nil):>(1:>2:>3:>Nil):>Nil >>> xss (1 :> 2 :> 3 :> Nil) :> (1 :> 2 :> 3 :> Nil) :> (1 :> 2 :> 3 :> Nil) :> Nil >>> rotateMatrix xss (1 :> 2 :> 3 :> Nil) :> (3 :> 1 :> 2 :> Nil) :> (2 :> 3 :> 1 :> Nil) :> Nil
concatMap :: forall a (m :: Nat) b (n :: Nat) . (a -> Vec m b) -> Vec n a -> Vec (n * m) bclash-prelude Clash.Explicit.Prelude.Safe Map a function over all the elements of a vector and concatentate the resulting vectors.
>>> concatMap (replicate d3) (1:>2:>3:>Nil) 1 :> 1 :> 1 :> 2 :> 2 :> 2 :> 3 :> 3 :> 3 :> Nil
imap :: forall (n :: Nat) a b . KnownNat n => (Index n -> a -> b) -> Vec n a -> Vec n bclash-prelude Clash.Explicit.Prelude.Safe Apply a function of every element of a vector and its index.
>>> :t imap (+) (2 :> 2 :> 2 :> 2 :> Nil) imap (+) (2 :> 2 :> 2 :> 2 :> Nil) :: Vec 4 (Index 4) >>> imap (+) (2 :> 2 :> 2 :> 2 :> Nil) 2 :> 3 :> *** Exception: X: Clash.Sized.Index: result 4 is out of bounds: [0..3] ... >>> imap (\i a -> extend (bitCoerce i) + a) (2 :> 2 :> 2 :> 2 :> Nil) :: Vec 4 (Unsigned 8) 2 :> 3 :> 4 :> 5 :> Nil
"imap f xs" corresponds to the following circuit layout:-
clash-prelude Clash.Explicit.Prelude.Safe Apply a function to every element of a vector and the element's position (as an SNat value) in the vector.
>>> let rotateMatrix = smap (flip rotateRightS) >>> let xss = (1:>2:>3:>Nil):>(1:>2:>3:>Nil):>(1:>2:>3:>Nil):>Nil >>> xss (1 :> 2 :> 3 :> Nil) :> (1 :> 2 :> 3 :> Nil) :> (1 :> 2 :> 3 :> Nil) :> Nil >>> rotateMatrix xss (1 :> 2 :> 3 :> Nil) :> (3 :> 1 :> 2 :> Nil) :> (2 :> 3 :> 1 :> Nil) :> Nil
concatMap :: forall a (m :: Nat) b (n :: Nat) . (a -> Vec m b) -> Vec n a -> Vec (n * m) bclash-prelude Clash.Prelude Map a function over all the elements of a vector and concatentate the resulting vectors.
>>> concatMap (replicate d3) (1:>2:>3:>Nil) 1 :> 1 :> 1 :> 2 :> 2 :> 2 :> 3 :> 3 :> 3 :> Nil
imap :: forall (n :: Nat) a b . KnownNat n => (Index n -> a -> b) -> Vec n a -> Vec n bclash-prelude Clash.Prelude Apply a function of every element of a vector and its index.
>>> :t imap (+) (2 :> 2 :> 2 :> 2 :> Nil) imap (+) (2 :> 2 :> 2 :> 2 :> Nil) :: Vec 4 (Index 4) >>> imap (+) (2 :> 2 :> 2 :> 2 :> Nil) 2 :> 3 :> *** Exception: X: Clash.Sized.Index: result 4 is out of bounds: [0..3] ... >>> imap (\i a -> extend (bitCoerce i) + a) (2 :> 2 :> 2 :> 2 :> Nil) :: Vec 4 (Unsigned 8) 2 :> 3 :> 4 :> 5 :> Nil
"imap f xs" corresponds to the following circuit layout: