Drastic Prelude changes imminent

Herbert Valerio Riedel hvr at gnu.org
Tue Feb 3 21:49:06 UTC 2015

On 2015-02-03 at 20:51:04 +0100, davean wrote:


>> I think the 'breakage' is mostly used as mentioning things that work
>> on lists, while they now work on Foldable/Traversables. For example,
>> LYAH mentions "length takes a list and returns its length,
>> obviously.", which isn't true anymore in the strictest sense, it takes
>> any Foldable. However, you could argue that this text is just
>> specialization, and that it's still true. There seem to be no things
>> that are generalized in the section about types, and soon after type
>> classes are already introduced.  Real World Haskell is slightly more
>> "broken", for example, it lists:
>> ghci> :type null
>> null :: [a] -> Bool
>> Which isn't true anymore, it would now give "Foldable t => t a -> Bool".

That's not worse than what RWH already does for the 'Monad m =>'

| Tip: These functions actually work for more than just I/O; they work for
|      any Monad. For now, wherever you see "M", just think "IO". Also,
|      functions that end with an underscore typically discard their
|      result. 2 comments

So such tutorials already do lie a little bit for the sake of easing
beginners in and then eventually rip the bandaids off. We shouldn't
assume beginners are that dumb they can't make that leap...

On a related matter, beginner books like the very popular LYAH or also
the more recent "Beginning Haskell" do introduce and actually recommend
the Foldable/Traversable abstraction with words like

| Because there are so many data structures that work nicely with folds,
| the Foldable type class was introduced. Much like Functor is for
| things that can be mapped over, Foldable is for things that can be
| folded up!


| As you saw in the previous chapter, lots of different algorithms can be
| expressed using folds. The module Data.Foldable includes most of them,
| like maximum or elem. One easy way to make your functions more general
| is hiding the functions with those names from the Prelude and importing
| the ones using Foldable.

...and go on to promote their use with the words

| But now that you know about them, you should aim for the largest
| degree of abstraction that you can achieve.

So, generalisations such as Foldable/Traversable are in fact taught (and
recommended) to beginners via books, and I'd even go as far as saying
that those in teaching positions who withold that knowledge from their
students are doing them a disservice.

So, Foldable/Traversable is not going away. Its use is rather going to
increase the more newcomers read those books, so we should rather
embrace it to avoid sending mixed signals to newcomers...


More information about the Libraries mailing list