Hoogle Search

Within LTS Haskell 24.4 (ghc-9.10.2)

Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.

  1. foldl' :: (Traversable t, Num a, Reifies s W) => (BVar s b -> BVar s a -> BVar s b) -> BVar s b -> BVar s (t a) -> BVar s b

    backprop Prelude.Backprop.Num

    foldl', but with Num constraints instead of Backprop constraints.

  2. foldl' :: Foldable t => (b -> a -> b) -> b -> t a -> b

    cabal-install-solver Distribution.Solver.Compat.Prelude

    Left-associative fold of a structure but with strict application of the operator. This ensures that each step of the fold is forced to Weak Head Normal Form before being applied, avoiding the collection of thunks that would otherwise occur. This is often what you want to strictly reduce a finite structure to a single strict result (e.g. sum). For a general Foldable structure this should be semantically identical to,

    foldl' f z = foldl' f z . toList
    

  3. foldl1 :: (a -> a -> a) -> NonEmpty a -> a

    cabal-install-solver Distribution.Solver.Compat.Prelude

    No documentation available.

  4. foldl' :: Foldable t => (b -> a -> b) -> b -> t a -> b

    calligraphy Calligraphy.Prelude

    Left-associative fold of a structure but with strict application of the operator. This ensures that each step of the fold is forced to Weak Head Normal Form before being applied, avoiding the collection of thunks that would otherwise occur. This is often what you want to strictly reduce a finite structure to a single strict result (e.g. sum). For a general Foldable structure this should be semantically identical to,

    foldl' f z = foldl' f z . toList
    

  5. foldl1 :: Foldable t => (a -> a -> a) -> t a -> a

    calligraphy Calligraphy.Prelude

    A variant of foldl that has no base case, and thus may only be applied to non-empty structures. This function is non-total and will raise a runtime exception if the structure happens to be empty.

    foldl1 f = foldl1 f . toList
    

    Examples

    Basic usage:
    >>> foldl1 (+) [1..4]
    10
    
    >>> foldl1 (+) []
    *** Exception: Prelude.foldl1: empty list
    
    >>> foldl1 (+) Nothing
    *** Exception: foldl1: empty structure
    
    >>> foldl1 (-) [1..4]
    -8
    
    >>> foldl1 (&&) [True, False, True, True]
    False
    
    >>> foldl1 (||) [False, False, True, True]
    True
    
    >>> foldl1 (+) [1..]
    * Hangs forever *
    

  6. foldlM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b

    calligraphy Calligraphy.Prelude

    Left-to-right monadic fold over the elements of a structure. Given a structure t with elements (a, b, ..., w, x, y), the result of a fold with an operator function f is equivalent to:

    foldlM f z t = do
    aa <- f z a
    bb <- f aa b
    ...
    xx <- f ww x
    yy <- f xx y
    return yy -- Just @return z@ when the structure is empty
    
    For a Monad m, given two functions f1 :: a -> m b and f2 :: b -> m c, their Kleisli composition (f1 >=> f2) :: a -> m c is defined by:
    (f1 >=> f2) a = f1 a >>= f2
    
    Another way of thinking about foldlM is that it amounts to an application to z of a Kleisli composition:
    foldlM f z t =
    flip f a >=> flip f b >=> ... >=> flip f x >=> flip f y $ z
    
    The monadic effects of foldlM are sequenced from left to right. If at some step the bind operator (>>=) short-circuits (as with, e.g., mzero in a MonadPlus), the evaluated effects will be from an initial segment of the element sequence. If you want to evaluate the monadic effects in right-to-left order, or perhaps be able to short-circuit after processing a tail of the sequence of elements, you'll need to use foldrM instead. If the monadic effects don't short-circuit, the outermost application of f is to the rightmost element y, so that, ignoring effects, the result looks like a left fold:
    ((((z `f` a) `f` b) ... `f` w) `f` x) `f` y
    

    Examples

    Basic usage:
    >>> let f a e = do { print e ; return $ e : a }
    
    >>> foldlM f [] [0..3]
    0
    1
    2
    3
    [3,2,1,0]
    

  7. foldl1 :: forall a (n :: Natural) . (a -> a -> a) -> Vec (n + 1) a -> a

    clash-prelude Clash.Explicit.Prelude

    foldl1 is a variant of foldl that has no starting value argument, and thus must be applied to non-empty vectors.

    foldl1 f (x1 :> x2 :> x3 :> ... :> xn :> Nil) == (...((x1 `f` x2) `f` x3) `f`...) `f` xn
    foldl1 f (x1 :> Nil)                          == x1
    foldl1 f Nil                                  == TYPE ERROR
    
    >>> foldl1 (/) (1 :> 5 :> 4 :> 3 :> 2 :> Nil)
    8.333333333333333e-3
    
    "foldl1 f xs" corresponds to the following circuit layout: NB: "foldl1 f z xs" produces a linear structure, which has a depth, or delay, of O(length xs). Use fold if your binary operator f is associative, as "fold f xs" produces a structure with a depth of O(log_2(length xs)).

  8. foldl1 :: forall a (n :: Natural) . (a -> a -> a) -> Vec (n + 1) a -> a

    clash-prelude Clash.Explicit.Prelude.Safe

    foldl1 is a variant of foldl that has no starting value argument, and thus must be applied to non-empty vectors.

    foldl1 f (x1 :> x2 :> x3 :> ... :> xn :> Nil) == (...((x1 `f` x2) `f` x3) `f`...) `f` xn
    foldl1 f (x1 :> Nil)                          == x1
    foldl1 f Nil                                  == TYPE ERROR
    
    >>> foldl1 (/) (1 :> 5 :> 4 :> 3 :> 2 :> Nil)
    8.333333333333333e-3
    
    "foldl1 f xs" corresponds to the following circuit layout: NB: "foldl1 f z xs" produces a linear structure, which has a depth, or delay, of O(length xs). Use fold if your binary operator f is associative, as "fold f xs" produces a structure with a depth of O(log_2(length xs)).

  9. foldl1 :: forall a (n :: Natural) . (a -> a -> a) -> Vec (n + 1) a -> a

    clash-prelude Clash.Prelude

    foldl1 is a variant of foldl that has no starting value argument, and thus must be applied to non-empty vectors.

    foldl1 f (x1 :> x2 :> x3 :> ... :> xn :> Nil) == (...((x1 `f` x2) `f` x3) `f`...) `f` xn
    foldl1 f (x1 :> Nil)                          == x1
    foldl1 f Nil                                  == TYPE ERROR
    
    >>> foldl1 (/) (1 :> 5 :> 4 :> 3 :> 2 :> Nil)
    8.333333333333333e-3
    
    "foldl1 f xs" corresponds to the following circuit layout: NB: "foldl1 f z xs" produces a linear structure, which has a depth, or delay, of O(length xs). Use fold if your binary operator f is associative, as "fold f xs" produces a structure with a depth of O(log_2(length xs)).

  10. foldl1 :: forall a (n :: Natural) . (a -> a -> a) -> Vec (n + 1) a -> a

    clash-prelude Clash.Prelude.Safe

    foldl1 is a variant of foldl that has no starting value argument, and thus must be applied to non-empty vectors.

    foldl1 f (x1 :> x2 :> x3 :> ... :> xn :> Nil) == (...((x1 `f` x2) `f` x3) `f`...) `f` xn
    foldl1 f (x1 :> Nil)                          == x1
    foldl1 f Nil                                  == TYPE ERROR
    
    >>> foldl1 (/) (1 :> 5 :> 4 :> 3 :> 2 :> Nil)
    8.333333333333333e-3
    
    "foldl1 f xs" corresponds to the following circuit layout: NB: "foldl1 f z xs" produces a linear structure, which has a depth, or delay, of O(length xs). Use fold if your binary operator f is associative, as "fold f xs" produces a structure with a depth of O(log_2(length xs)).

Page 6 of many | Previous | Next