Open chris-martin opened 2 years ago
@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?
@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.
I've gotten through
Foldable
andFunctor
, 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, andTraversable
will really work better in a new lesson afterApplicative
andMonad
. I had originally thought I could get through an introduction to traversal by just always usingIO
as the context and hand-waving over theApplicative
constraint, but the more I think of it the more I think we need to get toApplicative
/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 withFoldable
(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 areFoldable
because this class pretty much only describes container data structures.