[GHC] #13573: Add Foldable1 / Traversable1 to base

#13573: Add Foldable1 / Traversable1 to base -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: #10365 Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- `NonEmpty` and `Semigroup` are in ''base'' and 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], [https://hackage.haskell.org/package/semigroupoids-5.1/docs/Data- Semigroup-Traversable.html Traversable1] in ''base'' as well. `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 #49] and this [https://github.com/arkeet/difference/blob/0f0e14f51cf1ecd7ebf2d8c52204bd91ae... github] page) {{{#!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 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13573 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13573: Add Foldable1 / Traversable1 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: | -------------------------------------+------------------------------------- Changes (by Iceland_jack): * type: bug => feature request @@ -1,1 +1,1 @@ - `NonEmpty` and `Semigroup` are in ''base'' and are on our way to add + `NonEmpty` and `Semigroup` are in ''base'' and we are on our way to add @@ -43,1 +43,1 @@ - controversial + controversial but I never liked so many partial functions in `Foldable`. 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], [https://hackage.haskell.org/package/semigroupoids-5.1/docs/Data- Semigroup-Traversable.html Traversable1] in ''base'' as well. `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 #49] and this [https://github.com/arkeet/difference/blob/0f0e14f51cf1ecd7ebf2d8c52204bd91ae... github] page) {{{#!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:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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,3 +5,1 @@ - Semigroup-Foldable.html Foldable1], - [https://hackage.haskell.org/package/semigroupoids-5.1/docs/Data- - Semigroup-Traversable.html Traversable1] in ''base'' as well. + Semigroup-Foldable.html Foldable1] in ''base'' as well. 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. `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 #49] and this [https://github.com/arkeet/difference/blob/0f0e14f51cf1ecd7ebf2d8c52204bd91ae... github] page) {{{#!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:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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/0f0e14f51cf1ecd7ebf2d8c52204bd91ae... 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

#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: @@ -17,1 +17,1 @@ - If `Foldable1` we can make these functions total: + With `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/0f0e14f51cf1ecd7ebf2d8c52204bd91ae... github] page) With `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:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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: @@ -1,3 +1,1 @@ - `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 + This is a proposal to add @@ -5,2 +3,1 @@ - Semigroup-Foldable.html Foldable1] in ''base'' as well (`Foldable1` is - like `Foldable` for non-empty structures). + Semigroup-Foldable.html Foldable1] (non-empty `Foldable`) to base @@ -8,6 +5,14 @@ - `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 + {{{#!hs + -- Data.Semigroup.Foldable + class Foldable t => Foldable1 t where + fold1 :: Semigroup m => t m -> m + foldMap1 :: Semigroup m => (a -> m) -> t a -> m + + -- Possible methods (efficiency) + head1 :: t a -> a + last1 :: t a -> a + }}} + + along with instances and function that are only valid for non-empty + structures (details: [https://github.com/ekmett/semigroupoids/issues/49 + semigroupoids issue #49], @@ -15,3 +20,1 @@ - github] page) - - With `Foldable1` we can make these functions total: + github]) @@ -39,2 +42,2 @@ - There is also the possibility of adding further functions such as `foldM`, - `foldM_`, `foldrM` and `foldlM` for non-empty structures. + Adding `foldM`, `foldM_`, `foldrM` and `foldlM` for non-empty structures + is also a possibility. @@ -42,3 +45,10 @@ - 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`. + ---- + + Currently these are partial functions in `Foldable`. This proposal does + '''not''' propose replacing partial `Foldable` functions. + + ---- + + I wanted to test the waters before submitting it to the libraries mailing + list. This may be controversial but it gives us a path to avoid partial + functions in `Foldable`. New description: This is a proposal to add [https://hackage.haskell.org/package/semigroupoids-5.1/docs/Data- Semigroup-Foldable.html Foldable1] (non-empty `Foldable`) to base {{{#!hs -- Data.Semigroup.Foldable class Foldable t => Foldable1 t where fold1 :: Semigroup m => t m -> m foldMap1 :: Semigroup m => (a -> m) -> t a -> m -- Possible methods (efficiency) head1 :: t a -> a last1 :: t a -> a }}} along with instances and function that are only valid for non-empty structures (details: [https://github.com/ekmett/semigroupoids/issues/49 semigroupoids issue #49], [https://github.com/arkeet/difference/blob/0f0e14f51cf1ecd7ebf2d8c52204bd91ae... github]) {{{#!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) }}} Adding `foldM`, `foldM_`, `foldrM` and `foldlM` for non-empty structures is also a possibility. ---- Currently these are partial functions in `Foldable`. This proposal does '''not''' propose replacing partial `Foldable` functions. ---- I wanted to test the waters before submitting it to the libraries mailing list. This may be controversial but it gives us a path to avoid partial functions in `Foldable`. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13573#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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: @@ -12,2 +12,3 @@ - head1 :: t a -> a - last1 :: t a -> a + head1 :: t a -> a + last1 :: t a -> a + toNonEmpty :: t a -> Nonempty a New description: This is a proposal to add [https://hackage.haskell.org/package/semigroupoids-5.1/docs/Data- Semigroup-Foldable.html Foldable1] (non-empty `Foldable`) to base {{{#!hs -- Data.Semigroup.Foldable class Foldable t => Foldable1 t where fold1 :: Semigroup m => t m -> m foldMap1 :: Semigroup m => (a -> m) -> t a -> m -- Possible methods (efficiency) head1 :: t a -> a last1 :: t a -> a toNonEmpty :: t a -> Nonempty a }}} along with instances and function that are only valid for non-empty structures (details: [https://github.com/ekmett/semigroupoids/issues/49 semigroupoids issue #49], [https://github.com/arkeet/difference/blob/0f0e14f51cf1ecd7ebf2d8c52204bd91ae... github]) {{{#!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) }}} Adding `foldM`, `foldM_`, `foldrM` and `foldlM` for non-empty structures is also a possibility. ---- Currently these are partial functions in `Foldable`. This proposal does '''not''' propose replacing partial `Foldable` functions. ---- I wanted to test the waters before submitting it to the libraries mailing list. This may be controversial but it gives us a path to avoid partial functions in `Foldable`. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13573#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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: @@ -11,1 +11,1 @@ - -- Possible methods (efficiency) + -- Possible methods @@ -14,1 +14,1 @@ - toNonEmpty :: t a -> Nonempty a + toNonEmpty :: t a -> NonEmpty a New description: This is a proposal to add [https://hackage.haskell.org/package/semigroupoids-5.1/docs/Data- Semigroup-Foldable.html Foldable1] (non-empty `Foldable`) to base {{{#!hs -- Data.Semigroup.Foldable class Foldable t => Foldable1 t where fold1 :: Semigroup m => t m -> m foldMap1 :: Semigroup m => (a -> m) -> t a -> m -- Possible methods head1 :: t a -> a last1 :: t a -> a toNonEmpty :: t a -> NonEmpty a }}} along with instances and function that are only valid for non-empty structures (details: [https://github.com/ekmett/semigroupoids/issues/49 semigroupoids issue #49], [https://github.com/arkeet/difference/blob/0f0e14f51cf1ecd7ebf2d8c52204bd91ae... github]) {{{#!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) }}} Adding `foldM`, `foldM_`, `foldrM` and `foldlM` for non-empty structures is also a possibility. ---- Currently these are partial functions in `Foldable`. This proposal does '''not''' propose replacing partial `Foldable` functions. ---- I wanted to test the waters before submitting it to the libraries mailing list. This may be controversial but it gives us a path to avoid partial functions in `Foldable`. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13573#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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: @@ -7,3 +7,3 @@ - class Foldable t => Foldable1 t where - fold1 :: Semigroup m => t m -> m - foldMap1 :: Semigroup m => (a -> m) -> t a -> m + class Foldable f => Foldable1 f where + fold1 :: Semigroup m => f m -> m + foldMap1 :: Semigroup m => (a -> m) -> f a -> m @@ -12,3 +12,3 @@ - head1 :: t a -> a - last1 :: t a -> a - toNonEmpty :: t a -> NonEmpty a + head1 :: f a -> a + last1 :: f a -> a + toNonEmpty :: f a -> NonEmpty a @@ -36,1 +36,1 @@ - foldr1 :: Foldable1 t => (a -> a -> a) -> (t a -> a) + foldr1 :: Foldable1 f => (a -> a -> a) -> (f a -> a) @@ -39,1 +39,1 @@ - foldl1 :: Foldable1 t => (a -> a -> a) -> (t a -> a) + foldl1 :: Foldable1 f => (a -> a -> a) -> (f a -> a) New description: This is a proposal to add [https://hackage.haskell.org/package/semigroupoids-5.1/docs/Data- Semigroup-Foldable.html Foldable1] (non-empty `Foldable`) to base {{{#!hs -- Data.Semigroup.Foldable class Foldable f => Foldable1 f where fold1 :: Semigroup m => f m -> m foldMap1 :: Semigroup m => (a -> m) -> f a -> m -- Possible methods head1 :: f a -> a last1 :: f a -> a toNonEmpty :: f a -> NonEmpty a }}} along with instances and function that are only valid for non-empty structures (details: [https://github.com/ekmett/semigroupoids/issues/49 semigroupoids issue #49], [https://github.com/arkeet/difference/blob/0f0e14f51cf1ecd7ebf2d8c52204bd91ae... github]) {{{#!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 f => (a -> a -> a) -> (f a -> a) foldr1 f = unimprove . foldMap1 (\a -> Diff (f a) a) foldl1 :: Foldable1 f => (a -> a -> a) -> (f a -> a) foldl1 f = unimprove . getDual . foldMap1 (\a -> Dual $ Diff (flip f a) a) }}} Adding `foldM`, `foldM_`, `foldrM` and `foldlM` for non-empty structures is also a possibility. ---- Currently these are partial functions in `Foldable`. This proposal does '''not''' propose replacing partial `Foldable` functions. ---- I wanted to test the waters before submitting it to the libraries mailing list. This may be controversial but it gives us a path to avoid partial functions in `Foldable`. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13573#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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: @@ -24,1 +24,3 @@ - minimum1 :: (Ord a, Foldable1 f) => f a -> a + import qualified Data.Semigroup as S + + minimum1, maximum1 :: (Ord a, Foldable1 f) => f a -> a @@ -26,2 +28,0 @@ - - maximum1 :: (Ord a, Foldable1 f) => f a -> a @@ -30,1 +30,1 @@ - head1 :: Foldable1 f => f a -> a + head1, last1 :: Foldable1 f => f a -> a @@ -32,0 +32,1 @@ + last1 = S.getLast . foldMap1 S.Last @@ -33,4 +34,1 @@ - last1 :: Foldable1 f => f a -> a - last1 = S.getLast . foldMap1 S.Last - - foldr1 :: Foldable1 f => (a -> a -> a) -> (f a -> a) + foldr1, foldl1 :: Foldable1 f => (a -> a -> a) -> (f a -> a) @@ -38,2 +36,0 @@ - - foldl1 :: Foldable1 f => (a -> a -> a) -> (f a -> a) New description: This is a proposal to add [https://hackage.haskell.org/package/semigroupoids-5.1/docs/Data- Semigroup-Foldable.html Foldable1] (non-empty `Foldable`) to base {{{#!hs -- Data.Semigroup.Foldable class Foldable f => Foldable1 f where fold1 :: Semigroup m => f m -> m foldMap1 :: Semigroup m => (a -> m) -> f a -> m -- Possible methods head1 :: f a -> a last1 :: f a -> a toNonEmpty :: f a -> NonEmpty a }}} along with instances and function that are only valid for non-empty structures (details: [https://github.com/ekmett/semigroupoids/issues/49 semigroupoids issue #49], [https://github.com/arkeet/difference/blob/0f0e14f51cf1ecd7ebf2d8c52204bd91ae... github]) {{{#!hs import qualified Data.Semigroup as S minimum1, maximum1 :: (Ord a, Foldable1 f) => f a -> a minimum1 = S.getMin . foldMap1 S.Min maximum1 = S.getMax . foldMap1 S.Max head1, last1 :: Foldable1 f => f a -> a head1 = S.getFirst . foldMap1 S.First last1 = S.getLast . foldMap1 S.Last foldr1, foldl1 :: Foldable1 f => (a -> a -> a) -> (f a -> a) foldr1 f = unimprove . foldMap1 (\a -> Diff (f a) a) foldl1 f = unimprove . getDual . foldMap1 (\a -> Dual $ Diff (flip f a) a) }}} Adding `foldM`, `foldM_`, `foldrM` and `foldlM` for non-empty structures is also a possibility. ---- Currently these are partial functions in `Foldable`. This proposal does '''not''' propose replacing partial `Foldable` functions. ---- I wanted to test the waters before submitting it to the libraries mailing list. This may be controversial but it gives us a path to avoid partial functions in `Foldable`. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13573#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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: | -------------------------------------+------------------------------------- Comment (by Iceland_jack): Examples from [https://hackage.haskell.org/package/algebra-4.3/docs /Numeric-Algebra-Class.html alge][https://hackage.haskell.org/package/algebra-4.3/docs/Numeric- Additive-Class.html bra] package {{{#!hs class Additive r where (+) :: r -> r -> r sumWith1 :: Foldable1 f => (a -> r) -> f a -> r class Multiplicative r where (*) :: r -> r -> r productWith1 :: Foldable1 f => (a -> r) -> f a -> r }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13573#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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: @@ -9,1 +9,1 @@ - foldMap1 :: Semigroup m => (a -> m) -> f a -> m + foldMap1 :: Semigroup m => (a -> m) -> (f a -> m) New description: This is a proposal to add [https://hackage.haskell.org/package/semigroupoids-5.1/docs/Data- Semigroup-Foldable.html Foldable1] (non-empty `Foldable`) to base {{{#!hs -- Data.Semigroup.Foldable class Foldable f => Foldable1 f where fold1 :: Semigroup m => f m -> m foldMap1 :: Semigroup m => (a -> m) -> (f a -> m) -- Possible methods head1 :: f a -> a last1 :: f a -> a toNonEmpty :: f a -> NonEmpty a }}} along with instances and function that are only valid for non-empty structures (details: [https://github.com/ekmett/semigroupoids/issues/49 semigroupoids issue #49], [https://github.com/arkeet/difference/blob/0f0e14f51cf1ecd7ebf2d8c52204bd91ae... github]) {{{#!hs import qualified Data.Semigroup as S minimum1, maximum1 :: (Ord a, Foldable1 f) => f a -> a minimum1 = S.getMin . foldMap1 S.Min maximum1 = S.getMax . foldMap1 S.Max head1, last1 :: Foldable1 f => f a -> a head1 = S.getFirst . foldMap1 S.First last1 = S.getLast . foldMap1 S.Last foldr1, foldl1 :: Foldable1 f => (a -> a -> a) -> (f a -> a) foldr1 f = unimprove . foldMap1 (\a -> Diff (f a) a) foldl1 f = unimprove . getDual . foldMap1 (\a -> Dual $ Diff (flip f a) a) }}} Adding `foldM`, `foldM_`, `foldrM` and `foldlM` for non-empty structures is also a possibility. ---- Currently these are partial functions in `Foldable`. This proposal does '''not''' propose replacing partial `Foldable` functions. ---- I wanted to test the waters before submitting it to the libraries mailing list. This may be controversial but it gives us a path to avoid partial functions in `Foldable`. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13573#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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: | -------------------------------------+------------------------------------- Comment (by chshersh): If this type class will be added to `base` library one day (which I personally really like to see) I would love to add that it would be good to have `fold1'` function with strict semantic (similar to `foldl'`). Otherwise `fold1 $ map Sum (1 :| [2 .. 10^8])` would take infinite amount of time and memory to calculate and there will be no better way to do this. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13573#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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: | -------------------------------------+------------------------------------- Comment (by andrewthad): The name of the typeclass is a little unfortunate since the similarly named `Eq1`, `Show1`, etc. use the same suffix but with a very different meaning. Also, it's a little unfortunate that `Foldable1` doesn't have `foldl1`, `foldr1`, etc. Although there are already functions of the same name in `Foldable`, and there's no burning need to remove them any time soon, it would be nice to have a long-term plan to deprecate and remove them since they are a wart in the typeclass design. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13573#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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: | -------------------------------------+------------------------------------- Comment (by andrewthad): Those things aside, in general, I am in favor of getting `Foldable1` into `base` (with the same name that it currently has). I would like for the typeclass to have more methods though, and I'd like for there to be a longer-term plan around fixing `Foldable`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13573#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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: | -------------------------------------+------------------------------------- Comment (by recursion-ninja): A related discussion: https://github.com/ekmett/semigroupoids/issues/26 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13573#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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: | -------------------------------------+------------------------------------- Comment (by chshersh): Alternative naming option would be `NonEmptyFoldable` or `FoldableNE` or something similar. But this is either long or non-uniform. `Foldable1` is good enough. And we probably won't need type classes like `Eq1` and `Show1` in future since we have `QuantifiedConstraints` landed in GHC. In some moment of time they can be deprecated and removed. So we only need to prepare for StackOverflow and Reddit questions like ''Why `Eq1` and `Show1` are different from `Eq` and `Show` in not the same way as `Foldable1` from `Foldable`?''. But I guess this is manageable. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13573#comment:16 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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: | -------------------------------------+------------------------------------- Comment (by chessai): I've committed a differential for this to https://phabricator.haskell.org/D4812 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13573#comment:17 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13573: Add Foldable1 to base -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: feature request | Status: patch Priority: normal | Milestone: 8.8.1 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): Phab:D4812 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => patch * differential: => Phab:D4812 * milestone: => 8.8.1 Comment: Thanks chessai! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13573#comment:18 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13573: Add Foldable1 to base -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: feature request | Status: patch Priority: normal | Milestone: 8.8.1 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): Phab:D4812 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Iceland_jack): Thank you chessai -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13573#comment:19 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13573: Add Foldable1 to base -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: feature request | Status: patch Priority: normal | Milestone: 8.8.1 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): Phab:D4812 Wiki Page: | -------------------------------------+------------------------------------- Comment (by alpmestan): Quoting dfeuer's message from D4812:
I believe this change needs a formal libraries list proposal.
If that is indeed the case, is anyone interested in taking this to the libraries@ list? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13573#comment:20 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13573: Add Foldable1 to base -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: feature request | Status: patch Priority: normal | Milestone: 8.8.1 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, #15566 | Differential Rev(s): Phab:D4812 Wiki Page: | -------------------------------------+------------------------------------- Changes (by Iceland_jack): * related: #10365 => #10365, #15566 Comment: Also {{{#!hs maximumBy :: Foldable1 f1 => (a -> a -> Ordering) -> (f1 a -> a) maximumBy cmp = foldl1_ max' where max' x y = case cmp x y of GT -> x _ -> y minimumBy :: Foldable1 f1 => (a -> a -> Ordering) -> (f1 a -> a) minimumBy cmp = foldl1_ min' where min' x y = case cmp x y of GT -> y _ -> x }}} and per #15566 {{{#!hs maximumOn, minimumOn :: Foldable1 f1 => Ord cmp => (a -> cmp) -> (f1 a -> a) maximumOn = maximumBy . comparing minimumOn = minimumBy . comparing }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13573#comment:21 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13573: Add Foldable1 to base -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: feature request | Status: patch Priority: normal | Milestone: 8.10.1 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, #15566 | Differential Rev(s): Phab:D4812 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * milestone: 8.8.1 => 8.10.1 Comment: This won't happen for 8.8. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13573#comment:22 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC