Haskell Foldable Wast

Henrik Nilsson Henrik.Nilsson at nottingham.ac.uk
Thu Feb 18 10:54:29 UTC 2016


John Wiegley wrote:

 > I think the fact that toList (3,4) has a meaning that is not obvious
 > to the layman is a teaching matter.

Well, I would not characterise many of those who have raised concerns
about this as "laymen".

With a couple of decades of Haskell and CS teaching experience, and a
couple more of general programming experience, I don't consider myself
a layman either (and I hope that does not come across as arrogant).

Yet, things like:

 > length (1, 2) = 1
 > fold ("foo", "bar") = "bar"
 > toList (3,4) = [4]
 > elem 1 (1,2) = False

simply makes no sense to me whatsoever: neither intuitively,
nor in terms of compelling practical use cases.

And as to teaching this to a class: well, if we want to stop
our students from considering Haskell as a serious programming
language, I can see no better way than the above. Our students
here would be in laughing fits throughout their degrees.

I read (x,4), in a Foldable
 > context, as an "annotated 4", and not as some kind of shorthand for a
 > two-element collection.

Personally, if I wanted to introduce annotated numbers, I'd introduce
a new type to clearly convey that idea. Yes, a bit more to write,
but the end result is code that conveys the ideas behind it in a clear
manner. After all, code is (broadly) written once, but read many times.

As to making tuples functor instances, that can only be done by
arbitrarily imbuing one of the fields with a special status.
I have to ask: Why? After all, taking pairs as an example, the
*essence* of a pair is that there are two projection functions, one for
each field.

So, if I am now interested in applying a function to the fields,
why should only one of the fields be granted that privilege?
That's just not symmetrical and goes against the very idea of tuples.

And whenever I have wanted to map on tuple fields (which I do from
time to time), I most certainly want the ability to map on any field.

As to tuples as instances of foldable: Why?  There isn't any structure
to fold!

By all means, if some care about making tuples be instances of
functor and foldable etc., put those instances in a separate module,
thus saving the rest of the (Haskell) world from the cognitive
burden of even beginning to make any useful sense of

    length (1, 2) = 1

And allowing us to spend valuable teaching time on aspects of
Haskell that actually might persuade our students to take
Haskell seriously.



Henrik Nilsson
School of Computer Science
The University of Nottingham
nhn at cs.nott.ac.uk

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.

More information about the Libraries mailing list