Add NonEmptyMap and NonEmptySet to containers

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Add NonEmptyMap and NonEmptySet to containers

V.Liepelt
Hi John,

I saw your thread about non-empty containers today. Why not call them `Set1`, `Map1`, etc. in analogy to `many`/`many1` from parser combinators?

I think most agree that `NonEmpty` is not a great name—I couldn’t summarise it better than Andreas: "NonEmpty what?”. Hence I always do the following:

```
import Data.List.NonEmpty (NonEmpty)
import qualified Data.List.NonEmpty as List1

type List1 = NonEmpty
```

In fact I just hoogled for this and noticed that the rebase package seems to do this too.

More anecdotal precedent: recently a colleague wrote a datatype isomorphic to `(a, a, [a])` and called it something not quite as ridiculous as `ListWithAtLeastTwoElements`, so I suggested `List2` and everybody involved was happy with that.

Vilem
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Add NonEmptyMap and NonEmptySet to containers

Alexandre Esteves
I do like the sound of `instance Foldable1 Set1` more than I do `instance NonEmptyFoldable NonEmptySet`

On Wed, Sep 18, 2019 at 11:49 AM V.Liepelt <[hidden email]> wrote:
Hi John,

I saw your thread about non-empty containers today. Why not call them `Set1`, `Map1`, etc. in analogy to `many`/`many1` from parser combinators?

I think most agree that `NonEmpty` is not a great name—I couldn’t summarise it better than Andreas: "NonEmpty what?”. Hence I always do the following:

```
import Data.List.NonEmpty (NonEmpty)
import qualified Data.List.NonEmpty as List1

type List1 = NonEmpty
```

In fact I just hoogled for this and noticed that the rebase package seems to do this too.

More anecdotal precedent: recently a colleague wrote a datatype isomorphic to `(a, a, [a])` and called it something not quite as ridiculous as `ListWithAtLeastTwoElements`, so I suggested `List2` and everybody involved was happy with that.

Vilem
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Add NonEmptyMap and NonEmptySet to containers

Zemyla
Counterpoint: Generic1 refers to a higher kinded Generic, not a nonempty one.

On Thu, Sep 19, 2019, 20:17 Alexandre Esteves <[hidden email]> wrote:
I do like the sound of `instance Foldable1 Set1` more than I do `instance NonEmptyFoldable NonEmptySet`

On Wed, Sep 18, 2019 at 11:49 AM V.Liepelt <[hidden email]> wrote:
Hi John,

I saw your thread about non-empty containers today. Why not call them `Set1`, `Map1`, etc. in analogy to `many`/`many1` from parser combinators?

I think most agree that `NonEmpty` is not a great name—I couldn’t summarise it better than Andreas: "NonEmpty what?”. Hence I always do the following:

```
import Data.List.NonEmpty (NonEmpty)
import qualified Data.List.NonEmpty as List1

type List1 = NonEmpty
```

In fact I just hoogled for this and noticed that the rebase package seems to do this too.

More anecdotal precedent: recently a colleague wrote a datatype isomorphic to `(a, a, [a])` and called it something not quite as ridiculous as `ListWithAtLeastTwoElements`, so I suggested `List2` and everybody involved was happy with that.

Vilem
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Add NonEmptyMap and NonEmptySet to containers

Ruben Astudillo
In reply to this post by Alexandre Esteves
On 19-09-19 22:17, Alexandre Esteves wrote:
> I do like the sound of `instance Foldable1 Set1` more than I do
> `instance NonEmptyFoldable NonEmptySet`
> <https://hackage.haskell.org/package/semigroupoids-5.3.3/docs/Data-Semigroup-Foldable.html#t:Foldable1>

I prefer it too, I just wish (future) documentation included a little
explanation on why the suffix 1 was put.

--
-- Ruben
-- PGP: 4EE9 28F7 932E F4AD
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Add NonEmptyMap and NonEmptySet to containers

Andreas Abel-2
I think the origin of the suffix 1 is e.g. the function

   foldr1 :: (a -> a -> a) -> [a] -> a

which is a fold for non-empty lists only.

That use of "1" might be older than the use of "1" for order-1 type
constructors.

On 2019-09-20 03:56, Ruben Astudillo wrote:
> On 19-09-19 22:17, Alexandre Esteves wrote:
>> I do like the sound of `instance Foldable1 Set1` more than I do
>> `instance NonEmptyFoldable NonEmptySet`
>> <https://hackage.haskell.org/package/semigroupoids-5.3.3/docs/Data-Semigroup-Foldable.html#t:Foldable1>
>
> I prefer it too, I just wish (future) documentation included a little
> explanation on why the suffix 1 was put.
>

--
Andreas Abel  <><      Du bist der geliebte Mensch.

Department of Computer Science and Engineering
Chalmers and Gothenburg University, Sweden

[hidden email]
http://www.cse.chalmers.se/~abela/
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Add NonEmptyMap and NonEmptySet to containers

Oleg Grenrus
In reply to this post by Ruben Astudillo
Relating to Foldable1/NonEmptyFoldable, based in another discussion (in
my foldable1 to base proposal), it looks like it might be called
Semifoldable

See https://mail.haskell.org/pipermail/libraries/2019-October/030030.html

Yet, Semiset is different thing (based on wikipedia:
https://en.wikipedia.org/wiki/Semiset). NonEmptySet is a good name, it
doesn't need explanation. If someone feels that it's too long, they can
introduce `type NESet = NonEmptySet` alias in their development.

- Oleg

On 20.9.2019 4.56, Ruben Astudillo wrote:
> On 19-09-19 22:17, Alexandre Esteves wrote:
>> I do like the sound of `instance Foldable1 Set1` more than I do
>> `instance NonEmptyFoldable NonEmptySet`
>> <https://hackage.haskell.org/package/semigroupoids-5.3.3/docs/Data-Semigroup-Foldable.html#t:Foldable1>
> I prefer it too, I just wish (future) documentation included a little
> explanation on why the suffix 1 was put.
>
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Add NonEmptyMap and NonEmptySet to containers

Keith
Sorry about bikeshedding. However, 'semifoldable' would be super confusing.

If somebody saw 'semifoldMap' in the wild what would they think? Probably not that it can fold _more_ things than 'foldMap'.

'NonemptyFoldable', 'Semigroup.Foldable', 'SemigroupFoldable', and 'Foldable1', with 'sfoldMap', 'sgFoldMap', 'nonemptyFoldMap', or 'Semigroup.foldMap' may be long or meaningless to most, but at least they aren't actively misleading.

–Keith

On October 18, 2019 2:13:51 PM UTC, Oleg Grenrus <[hidden email]> wrote:
Relating to Foldable1/NonEmptyFoldable, based in another discussion (in 
my foldable1 to base proposal), it looks like it might be called
Semifoldable

See https://mail.haskell.org/pipermail/libraries/2019-October/030030.html

Yet, Semiset is different thing (based on wikipedia:
https://en.wikipedia.org/wiki/Semiset). NonEmptySet is a good name, it
doesn't need explanation. If someone feels that it's too long, they can
introduce `type NESet = NonEmptySet` alias in their development.

- Oleg

On 20.9.2019 4.56, Ruben Astudillo wrote:
On 19-09-19 22:17, Alexandre Esteves wrote:
I do like the sound of `instance Foldable1 Set1` more than I do
`instance NonEmptyFoldable NonEmptySet`
<https://hackage.haskell.org/package/semigroupoids-5.3.3/docs/Data-Semigroup-Foldable.html#t:Foldable1>
I prefer it too, I just wish (future) documentation included a little
explanation on why the suffix 1 was put.


Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

--
Sent from my phone with K-9 Mail.
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Add NonEmptyMap and NonEmptySet to containers

Oleg Grenrus

Please reply to the "Add Data.Foldable1 to base" -thread to keep the discussion in one place.
Otherwise this opinion will most likely be ignored.

- Oleg

P.S. That said, foldMap1/semifoldMap/... can fold over *less* things. It can fold over NonEmpty (list) but not over ordinary [].

On 18.10.2019 18.40, Keith wrote:
Sorry about bikeshedding. However, 'semifoldable' would be super confusing.

If somebody saw 'semifoldMap' in the wild what would they think? Probably not that it can fold _more_ things than 'foldMap'.

'NonemptyFoldable', 'Semigroup.Foldable', 'SemigroupFoldable', and 'Foldable1', with 'sfoldMap', 'sgFoldMap', 'nonemptyFoldMap', or 'Semigroup.foldMap' may be long or meaningless to most, but at least they aren't actively misleading.

–Keith

On October 18, 2019 2:13:51 PM UTC, Oleg Grenrus [hidden email] wrote:
Relating to Foldable1/NonEmptyFoldable, based in another discussion (in 
my foldable1 to base proposal), it looks like it might be called 
Semifoldable

See https://mail.haskell.org/pipermail/libraries/2019-October/030030.html

Yet, Semiset is different thing (based on wikipedia: 
https://en.wikipedia.org/wiki/Semiset). NonEmptySet is a good name, it 
doesn't need explanation. If someone feels that it's too long, they can 
introduce `type NESet = NonEmptySet` alias in their development.

- Oleg

On 20.9.2019 4.56, Ruben Astudillo wrote:
On 19-09-19 22:17, Alexandre Esteves wrote:
I do like the sound of `instance Foldable1 Set1` more than I do `instance NonEmptyFoldable NonEmptySet` <https://hackage.haskell.org/package/semigroupoids-5.3.3/docs/Data-Semigroup-Foldable.html#t:Foldable1>
I prefer it too, I just wish (future) documentation included a little explanation on why the suffix 1 was put.

Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

--
Sent from my phone with K-9 Mail.
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Add Data.Foldable1 to base

John Ericson-2

Echoing Keith's point, "semi" to me means a weaker algebra; i.e. a super-class. Foldable => Semifoldable is thus totally wrong, "Semifoldable" is the sub-class. In particular. The Monoid and Semigroup constraints on their respective methods further show that the fold class hierarchy is *contravariant* with respect to the binary operator class hierarchy. Putting semi-* with semi-* only makes sense for something covariant (e.g. the if methods *returned* `Dict (Semigroup a)` etc).

Semimonad and Semiapplicative are fine with me (I don't really care, not worth fighting one way or the other) but strong -1 on Semifoldable.

John

On 10/18/19 12:10 PM, Oleg Grenrus wrote:

Please reply to the "Add Data.Foldable1 to base" -thread to keep the discussion in one place.
Otherwise this opinion will most likely be ignored.

- Oleg

P.S. That said, foldMap1/semifoldMap/... can fold over *less* things. It can fold over NonEmpty (list) but not over ordinary [].

On 18.10.2019 18.40, Keith wrote:
Sorry about bikeshedding. However, 'semifoldable' would be super confusing.

If somebody saw 'semifoldMap' in the wild what would they think? Probably not that it can fold _more_ things than 'foldMap'.

'NonemptyFoldable', 'Semigroup.Foldable', 'SemigroupFoldable', and 'Foldable1', with 'sfoldMap', 'sgFoldMap', 'nonemptyFoldMap', or 'Semigroup.foldMap' may be long or meaningless to most, but at least they aren't actively misleading.

–Keith

On October 18, 2019 2:13:51 PM UTC, Oleg Grenrus [hidden email] wrote:
Relating to Foldable1/NonEmptyFoldable, based in another discussion (in 
my foldable1 to base proposal), it looks like it might be called 
Semifoldable

See https://mail.haskell.org/pipermail/libraries/2019-October/030030.html

Yet, Semiset is different thing (based on wikipedia: 
https://en.wikipedia.org/wiki/Semiset). NonEmptySet is a good name, it 
doesn't need explanation. If someone feels that it's too long, they can 
introduce `type NESet = NonEmptySet` alias in their development.

- Oleg

On 20.9.2019 4.56, Ruben Astudillo wrote:
On 19-09-19 22:17, Alexandre Esteves wrote:
I do like the sound of `instance Foldable1 Set1` more than I do `instance NonEmptyFoldable NonEmptySet` <https://hackage.haskell.org/package/semigroupoids-5.3.3/docs/Data-Semigroup-Foldable.html#t:Foldable1>
I prefer it too, I just wish (future) documentation included a little explanation on why the suffix 1 was put.

Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

--
Sent from my phone with K-9 Mail.
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Add Data.Foldable1 to base

Henning Thielemann

On Tue, 22 Oct 2019, John Cotton Ericson wrote:

> Echoing Keith's point, "semi" to me means a weaker algebra; i.e. a
> super-class. Foldable => Semifoldable is thus totally wrong,
> "Semifoldable" is the sub-class.

me too
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Add Data.Foldable1 to base

Georgi Lyubenov
+1 for the "not calling it Semifoldable"

On Tue, Oct 22, 2019 at 9:34 PM Henning Thielemann <[hidden email]> wrote:

On Tue, 22 Oct 2019, John Cotton Ericson wrote:

> Echoing Keith's point, "semi" to me means a weaker algebra; i.e. a
> super-class. Foldable => Semifoldable is thus totally wrong,
> "Semifoldable" is the sub-class.

me too
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Add Data.Foldable1 to base

Carter Schonwald
This is a well articulated set of points. 

On Tue, Oct 22, 2019 at 3:31 PM Georgi Lyubenov <[hidden email]> wrote:
+1 for the "not calling it Semifoldable"

On Tue, Oct 22, 2019 at 9:34 PM Henning Thielemann <[hidden email]> wrote:

On Tue, 22 Oct 2019, John Cotton Ericson wrote:

> Echoing Keith's point, "semi" to me means a weaker algebra; i.e. a
> super-class. Foldable => Semifoldable is thus totally wrong,
> "Semifoldable" is the sub-class.

me too
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Add Data.Foldable1 to base

Andrew Martin
The question of "Is Semifoldable an appropriate name for Foldable1" has come up before on semigroupoids issue #26 [1]. This was Edward's commentary there:

> I don’t have a particular problem with the Semi prefix on Foldable and Traversable. Intuitively, Monoid/Applicative give you tools for construction. Foldable/Traversable give you tools for consumption using those tools. The variance is flipped so the inheritance relation also flips.

I'm not well-versed in any kind of graduate-level mathematics, so I have no idea whether or not Keith or Edward's argument makes more sense. I just wanted to include this in the discussion so that people could respond to it here.


On Mon, Nov 25, 2019 at 5:07 PM Carter Schonwald <[hidden email]> wrote:
This is a well articulated set of points. 

On Tue, Oct 22, 2019 at 3:31 PM Georgi Lyubenov <[hidden email]> wrote:
+1 for the "not calling it Semifoldable"

On Tue, Oct 22, 2019 at 9:34 PM Henning Thielemann <[hidden email]> wrote:

On Tue, 22 Oct 2019, John Cotton Ericson wrote:

> Echoing Keith's point, "semi" to me means a weaker algebra; i.e. a
> super-class. Foldable => Semifoldable is thus totally wrong,
> "Semifoldable" is the sub-class.

me too
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries


--
-Andrew Thaddeus Martin

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries