Functor, Applicative, Monad, Foldable, Traversable instances for (, , ) a b

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

Re: Functor, Applicative, Monad, Foldable, Traversable instances for (, , ) a b

Tony Morris-4
Right, length is particularly unfortunate in that it is a bad example
for the purposes of parametricity. We can express additional properties,
as well as types, to make up for this shortcoming. Still better than
relying on glyphs, which are notoriously unreliable, misleading,
inefficient and impratical to use to convey useful information about the
behaviour of a function.

I will leave out the expression of these properties, so as not to rob
anyone of a fun and useful exercise. Ultimately, I genuinely do not
care. I routinely work on teams with people who do not care. We use
other tools for reasoning about programs; I argue, they are more
efficient and reliable. If anyone wants to disagree, that's fine, call
it pineapples or whatever may be chosen, and we can all move on. I
simply need that function, whatever it might be called.

PS: in a dream land, where hardware efficiencies are of no concern,
length = fmap (const ()).


On 06/04/17 18:12, Henrik Nilsson wrote:

> On 04/06/2017 04:15 AM, Tony Morris wrote:
>> By "length" here I mean, the function whose name is lima echo november
>> golf tango hotel. I truly do not care what it is called. Follow the
>> types, and the types of the types.
>
> I think the nub of the matter is that the types (and the types of the
> types) (in a language like Haskell) actually are not enough. There are
> (literally) infinitely many functions with the same type as "length".
> One might argue that few of those make "sense", but that is always
> going to be a precarious argument unless the setting is made clear.
>
> More generally, if we were to extrapolate and truly refer to things
> by their full specification, then that would be very cumbersome indeed.
> By analogy, mathematical theorems are full specifications, and they
> usually have names.
>
> Names matter, at least to most people (I dare guess), and in particular
> when we rely on the names to convey missing information, as is the
> case with "length" given its (Haskell) type.
>
> Best,
>
> /Henrik
>
>
>
>
>
> This message and any attachment are intended solely for the addressee
> and may contain confidential information. If you have received this
> message in error, please send it back to me, and immediately delete it.
> Please do not use, copy or disclose the information contained in this
> message or in any attachment.  Any views or opinions expressed by the
> author of this email do not necessarily reflect the views of the
> University of Nottingham.
>
> This message has been checked for viruses but the contents of an
> attachment may still contain software viruses which could damage your
> computer system, you are advised to perform your own checks. Email
> communications with the University of Nottingham may be monitored as
> permitted by UK legislation.
>
> _______________________________________________
> 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

signature.asc (499 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Functor, Applicative, Monad, Foldable, Traversable instances for (, , ) a b

Jon Fairbairn
In reply to this post by Tony Morris-4
Tony Morris <[hidden email]> writes:

> I don't think it is the "appropriate" set. It's an example. 0 is in the
> set of integers. The value 0 is in many sets.

OK, so I clearly do not understand your argument. The
implication I took from “and 0 is not an integer” is that the
foldable instance for ((,) a) should be present because it is
the zero case of something that has integers as its domain, and
I wanted to know what that something is.  If this was not the
intention of your argument, what was?

--
Jón Fairbairn                                 [hidden email]
http://www.chaos.org.uk/~jf/Stuff-I-dont-want.html  (updated 2014-04-05)

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

Re: Functor, Applicative, Monad, Foldable, Traversable instances for (, , ) a b

Tony Morris-4
These two things are true:

* 0 is in the set of integers
* ∀ a. ((,) a) is Foldable, and as one of many consequences, the length
of all values in the set ∀ a. ((,) a) is 1.

There are four possible positions to take on these claims:

1. Both are true.
2. Both are false.
3. The first true and second false.
4. The second true and the first false.

I respect arguments 1 and 2. If I chose 1 and you chose 2, I'd say "well
rightio then mate and cheers to that", we'd clink glasses and move on.
Same if it were vice versa.

I do not have the same respect for positions 3 and 4.

On 09/04/17 19:48, Jon Fairbairn wrote:

> Tony Morris <[hidden email]> writes:
>
>> I don't think it is the "appropriate" set. It's an example. 0 is in the
>> set of integers. The value 0 is in many sets.
> OK, so I clearly do not understand your argument. The
> implication I took from “and 0 is not an integer” is that the
> foldable instance for ((,) a) should be present because it is
> the zero case of something that has integers as its domain, and
> I wanted to know what that something is.  If this was not the
> intention of your argument, what was?
>


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

signature.asc (499 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Functor, Applicative, Monad, Foldable, Traversable instances for (, , ) a b

Benno Fünfstück
Correct me I I'm wrong but I believe Tony Morris is saying the following:

* not every operation defined for the integers "makes sense" for all integers. Example: '/' does not make sense in the case of 'x / 0'
* yet, we still include '0' in the integers even though not every operation makes sense for '0'
* -> not every operation in Foldable makes sense for `(,) a`
* -> but we also include `0` in the integers, so "not every operation makes sense" is not an argument to exclude `(,) a` from being foldable,
  just as `0` is not excluded from the integers.

Kind regards,
Benno

Tony Morris <[hidden email]> schrieb am So., 9. Apr. 2017 um 14:26 Uhr:
These two things are true:

* 0 is in the set of integers
* ∀ a. ((,) a) is Foldable, and as one of many consequences, the length
of all values in the set ∀ a. ((,) a) is 1.

There are four possible positions to take on these claims:

1. Both are true.
2. Both are false.
3. The first true and second false.
4. The second true and the first false.

I respect arguments 1 and 2. If I chose 1 and you chose 2, I'd say "well
rightio then mate and cheers to that", we'd clink glasses and move on.
Same if it were vice versa.

I do not have the same respect for positions 3 and 4.

On 09/04/17 19:48, Jon Fairbairn wrote:
> Tony Morris <[hidden email]> writes:
>
>> I don't think it is the "appropriate" set. It's an example. 0 is in the
>> set of integers. The value 0 is in many sets.
> OK, so I clearly do not understand your argument. The
> implication I took from “and 0 is not an integer” is that the
> foldable instance for ((,) a) should be present because it is
> the zero case of something that has integers as its domain, and
> I wanted to know what that something is.  If this was not the
> intention of your argument, what was?
>


_______________________________________________
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: Functor, Applicative, Monad, Foldable, Traversable instances for (, , ) a b

amindfv
Genuinely curious: can people point to specific examples in their (or others') code where the ((,) a) instance for Foldable is really helpful and difficult to replace?

Tom


El 9 abr 2017, a las 09:29, Benno Fünfstück <[hidden email]> escribió:

Correct me I I'm wrong but I believe Tony Morris is saying the following:

* not every operation defined for the integers "makes sense" for all integers. Example: '/' does not make sense in the case of 'x / 0'
* yet, we still include '0' in the integers even though not every operation makes sense for '0'
* -> not every operation in Foldable makes sense for `(,) a`
* -> but we also include `0` in the integers, so "not every operation makes sense" is not an argument to exclude `(,) a` from being foldable,
  just as `0` is not excluded from the integers.

Kind regards,
Benno

Tony Morris <[hidden email]> schrieb am So., 9. Apr. 2017 um 14:26 Uhr:
These two things are true:

* 0 is in the set of integers
* ∀ a. ((,) a) is Foldable, and as one of many consequences, the length
of all values in the set ∀ a. ((,) a) is 1.

There are four possible positions to take on these claims:

1. Both are true.
2. Both are false.
3. The first true and second false.
4. The second true and the first false.

I respect arguments 1 and 2. If I chose 1 and you chose 2, I'd say "well
rightio then mate and cheers to that", we'd clink glasses and move on.
Same if it were vice versa.

I do not have the same respect for positions 3 and 4.

On 09/04/17 19:48, Jon Fairbairn wrote:
> Tony Morris <[hidden email]> writes:
>
>> I don't think it is the "appropriate" set. It's an example. 0 is in the
>> set of integers. The value 0 is in many sets.
> OK, so I clearly do not understand your argument. The
> implication I took from “and 0 is not an integer” is that the
> foldable instance for ((,) a) should be present because it is
> the zero case of something that has integers as its domain, and
> I wanted to know what that something is.  If this was not the
> intention of your argument, what was?
>


_______________________________________________
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: Functor, Applicative, Monad, Foldable, Traversable instances for (, , ) a b

Francesco Ariis
On Sun, Apr 09, 2017 at 03:27:02PM -0500, [hidden email] wrote:
> Genuinely curious: can people point to specific examples in their (or
> others') code where the ((,) a) instance for Foldable is really helpful
> and difficult to replace?

I asked in the other thread, these are some of the answers I got:

Oliver Charles:
> Personally, I think it would be a shame to lose foldMap on EIther. I
> frequently foldMap over Maybe values (where mempty is suitable in case of
> "failure"), and I can certainly see myself doing the same thing with
> Either.

Oleg Grenrus:
> Anecdotally, today I wrote `foldMap toList`, to use as `Maybe (NonEmpty
> a) -> [a]`.
> Also I rely heavily in lens-based code on the `folded :: Fold (Maybe a)
> a`.

There haven't been replies on specific usage of functions length/sum/
maximum/etc.

I can't recall where, but someone else was making a point that a {-# Poison
something #-} pragma would fracture the ecosystem.
I don't think this holds much weight though, as library authors would most
likely toggle the flag in development (to avoid calling length Either,
etc.) and toggle it back on release.

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

Re: Functor, Applicative, Monad, Foldable, Traversable instances for (, , ) a b

amindfv
I did see those, but was hoping people could provide real code in the context of a library or code solving a particular problem. Real world Haskell, if you will :)

Tom


> El 9 abr 2017, a las 15:33, Francesco Ariis <[hidden email]> escribió:
>
>> On Sun, Apr 09, 2017 at 03:27:02PM -0500, [hidden email] wrote:
>> Genuinely curious: can people point to specific examples in their (or
>> others') code where the ((,) a) instance for Foldable is really helpful
>> and difficult to replace?
>
> I asked in the other thread, these are some of the answers I got:
>
> Oliver Charles:
>> Personally, I think it would be a shame to lose foldMap on EIther. I
>> frequently foldMap over Maybe values (where mempty is suitable in case of
>> "failure"), and I can certainly see myself doing the same thing with
>> Either.
>
> Oleg Grenrus:
>> Anecdotally, today I wrote `foldMap toList`, to use as `Maybe (NonEmpty
>> a) -> [a]`.
>> Also I rely heavily in lens-based code on the `folded :: Fold (Maybe a)
>> a`.
>
> There haven't been replies on specific usage of functions length/sum/
> maximum/etc.
>
> I can't recall where, but someone else was making a point that a {-# Poison
> something #-} pragma would fracture the ecosystem.
> I don't think this holds much weight though, as library authors would most
> likely toggle the flag in development (to avoid calling length Either,
> etc.) and toggle it back on release.
>
> -F
> _______________________________________________
> 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: Functor, Applicative, Monad, Foldable, Traversable instances for (, , ) a b

Simon Marechal
In reply to this post by amindfv
On 04/09/2017 10:27 PM, [hidden email] wrote:
> Genuinely curious: can people point to specific examples in their (or
> others') code where the ((,) a) instance for Foldable is really helpful
> and difficult to replace?

I use it quite often when prototyping stuff. I used it in two distinct
instances in the last two weeks.

As for the other usual suspects (Either, Maybe, etc.), their instances
are *really* useful, especially the Traversable, and especially in the REPL.

I write Haskell quite a lot now, and this only caused a bug *once*. I
didn't even realize these instances existed. But once I learned about
them, I never had a problem again (well, I can't be sure it isn't lying
dormant in some code I wrote).

On the other hand, I still get <<loop>> when I have a typo in my let
blocks. There are many other issues that seem more pressing to me.


Here is my plea, please step back, and consider the following before
getting worked up about these instances:

 * this is a very minor issue in the Haskell ecosystem
 * I believe most people are satisfied with the current state of
affairs. Every time I saw informal polls, such as [1], about what is
annoying about Haskell, this didn't even surface!
 * that ship has sailed, and another round of repeating the same old
argument will only clog the mailing list

[1]
https://www.reddit.com/r/haskell/comments/4f47ou/why_does_haskell_in_your_opinion_suck/
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Functor, Applicative, Monad, Foldable, Traversable instances for (, , ) a b

Jonathon Delgado
In reply to this post by Fumiaki Kinoshita
Code please? An actual, concrete example?
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
1234