[GHC] #13573: Add Foldable1 to base

GHC ghc-devs at haskell.org
Thu Apr 13 16:17:32 UTC 2017


#13573: Add Foldable1 to base
-------------------------------------+-------------------------------------
        Reporter:  Iceland_jack      |                Owner:  (none)
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.0.1
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:  #10365            |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Description changed by Iceland_jack:

@@ -5,1 +5,2 @@
- Semigroup-Foldable.html Foldable1] in ''base'' as well.
+ Semigroup-Foldable.html Foldable1] in ''base'' as well (`Foldable1` is
+ like `Foldable` for non-empty structures).
@@ -7,5 +8,5 @@
- `Foldable` has partial functions already, functions that only make sense
- for non-empty structures such as `foldr1`, `foldl1`, `minimum` and
- `maximum`. There are also functions which ''could'' be defined in terms of
- `Foldable` like `head` / `tail` (for definition of `unimprove` and `Diff`
- see [https://github.com/ekmett/semigroupoids/issues/49 semigroupoids issue
+ `Foldable` has partial functions, functions that only make sense for non-
+ empty structures such as `foldr1`, `foldl1`, `minimum` and `maximum`.
+ There are also functions which ''could'' be defined in terms of `Foldable`
+ like `head` / `tail` (for definition of `unimprove` and `Diff` see
+ [https://github.com/ekmett/semigroupoids/issues/49 semigroupoids issue
@@ -15,0 +16,2 @@
+
+ If `Foldable1` we can make these functions total:

New description:

 `NonEmpty` and `Semigroup` are in ''base'' and we are on our way to add
 `Semigroup` as a superclass of `Monoid` (#10365), this is a fine time to
 ask if we should include
 [https://hackage.haskell.org/package/semigroupoids-5.1/docs/Data-
 Semigroup-Foldable.html Foldable1] in ''base'' as well (`Foldable1` is
 like `Foldable` for non-empty structures).

 `Foldable` has partial functions, functions that only make sense for non-
 empty structures such as `foldr1`, `foldl1`, `minimum` and `maximum`.
 There are also functions which ''could'' be defined in terms of `Foldable`
 like `head` / `tail` (for definition of `unimprove` and `Diff` see
 [https://github.com/ekmett/semigroupoids/issues/49 semigroupoids issue
 #49] and this
 [https://github.com/arkeet/difference/blob/0f0e14f51cf1ecd7ebf2d8c52204bd91ae3b2969/src/Data/Semigroup/Difference.hs
 github] page)

 If `Foldable1` we can make these functions total:

 {{{#!hs
 minimum1 :: (Ord a, Foldable1 f) => f a -> a
 minimum1 = S.getMin . foldMap1 S.Min

 maximum1 :: (Ord a, Foldable1 f) => f a -> a
 maximum1 = S.getMax . foldMap1 S.Max

 head1 :: Foldable1 f => f a -> a
 head1 = S.getFirst . foldMap1 S.First

 last1 :: Foldable1 f => f a -> a
 last1 = S.getLast . foldMap1 S.Last

 foldr1 :: Foldable1 t => (a -> a -> a) -> (t a -> a)
 foldr1 f = unimprove . foldMap1 (\a -> Diff (f a) a)

 foldl1 :: Foldable1 t => (a -> a -> a) -> (t a -> a)
 foldl1 f = unimprove . getDual . foldMap1 (\a -> Dual $ Diff (flip f a) a)
 }}}

 There is also the possibility of adding further functions such as `foldM`,
 `foldM_`, `foldrM` and `foldlM` for non-empty structures.

 As usual I don't have more concrete ideas, but let's start by testing the
 waters before submitting a ghc-proposal. I understand this may be
 controversial but I never liked so many partial functions in `Foldable`.

--

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13573#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list