15th November 2008, 05:09 pm
This post is part four of the zip folding series inspired by Max Rabkin’s Beautiful folding post.
I meant to write one little post, but one post turned into four.
When I sense that something can be made simpler/clearer, I can’t leave it be.
To review:
- Part One related Max’s data representation of left folds to type class morphisms, a pattern that’s been steering me lately toward natural (inevitable) design of libraries.
- Part Two simplified that representation to help get to the essence of zipping, and in doing so lost the expressiveness necessary to define
Functor
and Applicative
instaces.
- Part Three proved the suitability of the zipping definitions in Part Two.
This post shows how to restore the Functor
and Applicative
(very useful composition tools) to folds but does so in a way that leaves the zipping functionality untouched.
This new layer is independent of folding and can be layered onto any zippable type.
You can get the code described below.
Edits:
- 2009-02-15: Simplified
WithCont
, collapsing two type parameters into one. Added functor comment about cfoldlc'
.
Continue reading ‘Enhancing a Zip’ »
This post is part four of the zip folding series inspired by Max Rabkin’s Beautiful folding post. I meant to write one little post, but one post turned into four....
15th November 2008, 01:30 pm
14th November 2008, 11:24 pm
My previous post, Another lovely example of type class morphisms, placed some standard structure around Max Rabkin’s Beautiful folding, using type class morphisms to confirm that the Functor
and Applicative
instances agreed with their inevitable meanings.
In the process of working out the Applicative
case, I realized the essence of fold zipping was getting a bit obscured.
This post simplifies Max’s Fold
data type a bit and shows how to zip strict left folds in the simpler setting.
You can get the code described here.
Edits:
- 2008-11-15: I renamed the
Pair
and Pair'
classes to Zip
and Zip'
.
Continue reading ‘More beautiful fold zipping’ »
My previous post, Another lovely example of type class morphisms, placed some standard structure around Max Rabkin’s Beautiful folding, using type class morphisms to confirm that the Functor and Applicative...
13th November 2008, 10:20 pm
I read Max Rabkin’s recent post Beautiful folding with great excitement.
He shows how to make combine multiple folds over the same list into a single pass, which can then drastically reduce memory requirements of a lazy functional program.
Max’s trick is giving folds a data representation and a way to combine representations that corresponds to combining the folds.
Peeking out from behind Max’s definitions is a lovely pattern I’ve been noticing more and more over the last couple of years, namely type class morphisms.
Continue reading ‘Another lovely example of type class morphisms’ »
I read Max Rabkin’s recent post Beautiful folding with great excitement. He shows how to make combine multiple folds over the same list into a single pass, which can then...