Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Foldable and Functor #54

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

chris-martin
Copy link
Contributor

I've gotten through Foldable and Functor, and I think it's best to cut this lesson off there - this one doesn't need to get any longer than it already is, and Traversable will really work better in a new lesson after Applicative and Monad. I had originally thought I could get through an introduction to traversal by just always using IO as the context and hand-waving over the Applicative constraint, but the more I think of it the more I think we need to get to Applicative/Monad first to solidify the "action" concept and to get to expand the set of tools we can use in example code.

This lesson is now retitled to "Constructor class basics: Foldable and Functor" because that's really the common theme here, how to think about what a constructor class is. Functor is the classical introduction to constructor classes, but it's a little bit overly mind-bending due to the number of type parameters involved as we shift from one container type to another, and because it requires generalizing over two different conceptual metaphors, containers and actions. Starting with Foldable (and sidestepping most of its complexity) I think offers a more gentle ramp appropriate to the fairly quick pace of haskell school. It's easier to get a grasp on what kinds of things are Foldable because this class pretty much only describes container data structures.

@@ -16,6 +16,7 @@ typeclasses:
- enumeration
- string-representation
- monoids
- iteration
- constructor-classes
- functors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would seem that this lesson is absorbed by the current one, is that right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's right. I had previously used "iteration" as the tag when the lesson was going to lead up to Traversable, since the whole thing was going to build up to what has been described as "essence of the iterator pattern", but since dropping Traversable from the lesson I renamed it from "iteration" to "constructor-classes".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realise now that the GitHub UI isn't the best when I thought I had highlighted one particular line. The functor lesson is also absorbed, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. The one called "functors" is Applicative/Monad.

@why-not-try-calmer
Copy link

why-not-try-calmer commented Jul 20, 2022

@chris-martin Just for my understanding, how does the part about Foldable relate to what you had written here?

As far as I can see the ground covered here goes a long way toward a lesson about folds. Sure, I could imagine additional contents tying up some loose ends about practical use-cases (i.e. early termination/recursion with foldr, common patterns by combining with Applicatives, etc) but I am not sure whether I should suggest additions to this chapter or submit a short addendum (admittedly that would be a little bit weird for the current format).

What do you think?

@chris-martin
Copy link
Contributor Author

@why-not-try-calmer The biggest question we don't answer in this lesson, because I think it's too difficult and too detached from the larger aim of covering the core typeclasses, is how you should decide whether to use a left/right or strict/nonstrict fold. We also don't at all discuss how toList and foldr are actually related to one another: We present "folding" as a way to "reduce" a list to a summary value, and yet folding with (:) builds up a new structure comparable to the orginal that is not actually "reduced" at all - leading into this idea that I guess is what we call "co-recursion".

What I was envisioning was a separate lesson dedicated to non-strict evaluation, that would cover a lot of the same stuff that the Data.Foldable module documentation currently discusses, but perhaps divorced from the Foldable class. I don't really know where it fits into Haskell School, though, because I suppose the entire school is not planned yet; I think the two lesson groups that we presently have outlined are too beginner-level for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants