Re: Strict folds without base case to `Data.Foldable`.

Viktor Dukhovni <[email protected]> Wed, 30 Jun 2021 15:52:06 -0400
Newsgroups gmane.comp.lang.haskell.libraries
Message-ID <[email protected]>
On Thu, Jul 01, 2021 at 12:01:51AM +0500, Ignat Insarov wrote:

> Whichever floats your boats folks. I am a user of Haskell and I
> require strict folds without base case. Further I dare not meddle.

To what sort of structure(s) are looking to apply a strict foldl1?

Since there is no `foldl1'` class method to override, no structures
have a specialised definition.  Therefore, a "default" definition
can be written outside the class:

    foldl1' :: Foldable t => (a -> a -> a) -> t a -> a
    foldl1' f = fromMaybe (errorWithoutStackTrace "foldl1': empty structure")
        . foldl' f' Nothing
      where
        f' ma x = Just $! case ma of
             Nothing -> x
             Just a  -> f a x

Which means you can just use this in your own code, it need not first
land in the Data.Foldable module for you to make use of it.

-- 
    Viktor.

P.S.  FWIW, apologies if I am misreading the tone of your message, but
it does sound "demanding" to me.  GHC is a free community project with
no large corporation invested in its development, all the contributors
want to help users, but this is easier to help users who are considerate
of those to would volunteer their time to help.
_______________________________________________
Libraries mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries