Using the work of Dr. Graham Hutton as our guide, we'll look at how to satisfy all of your list processing needs with one function, fold. First we'll start off simple by finding the length of a list, then we'll reverse a list, followed by and-ing and or-ing a list; all using fold. Next we'll look at implementing the higher order functions of: map, filter, and zip. Last we'll look at fold in action by using it on the Coin Changer kata. You'll never look at fold the same way again.
18. — Paul Feyerabend
Against Method
Chapter 16
“Fundamental conceptual change …
presupposes new world-views and
new languages capable of expressing
them.”
86. Filter
filter :: (α → Bool) → ([α] → [α])
filter p = fold (λx xs →
if p x then x : xs else xs) [ ]
if
Conj
[ ]
x1
x2
xn
Fold [x]
Given
We
[ ]
if
Conj
127. Books
• Richard Bird and Phil Wadler - Introduction to Functional
Programming. Prentice-Hall,1988.
http://usi-pl.github.io/lc/sp-2015/doc/Bird_Wadler.
%20Introduction%20to%20Functional%20Programming.
1ed.pdf
• Paul Feyerabend - Against Method. Verso, 2010.
• Michael Fogus - Functional JavaScript: Introducing
Functional Programming with Underscore.js. O’Reilly,
2013.
http://functionaljavascript.com/
128. Papers
• Erik Meijer, Maarten Fokkinga, and Ross Paterson -
“Functional Programming with Bananas, Lenses,
Envelopes and Barbed Wire”.
http://eprints.eemcs.utwente.nl/7281/01/db-
utwente-40501F46.pdf
• Graham Hutton - “A tutorial on the universality and
expressiveness of fold”.
http://www.cs.nott.ac.uk/~gmh/fold.pdf
129. Blog Posts
• Brian McNamara - “Catamorphisms, part one”
https://lorgonblog.wordpress.com/2008/04/05/
catamorphisms-part-one/
• Edward Kmett - “Catamorphisms”
https://www.fpcomplete.com/user/edwardk/recursion-
schemes/catamorphisms
131. Images (in order used)
• "Abbey Rd Studios" by Misterweiss at en.wikipedia - Transfered from en.wikipedia Transfer was stated to be made by User:Blast..
Licensed under Public Domain via Commons - https://commons.wikimedia.org/wiki/File:Abbey_Rd_Studios.jpg#/media/
File:Abbey_Rd_Studios.jpg
• "60s wallpaper" by Domincspics - Flickr. Licensed under CC BY 2.0 via Commons - https://commons.wikimedia.org/wiki/File:
60s_wallpaper.jpg#/media/File:60s_wallpaper.jpg
• "70's Wallpaper" by Liz Sullivan - Own work. Licensed under CC BY-SA 4.0 via Wikimedia Commons - https://
commons.wikimedia.org/wiki/File:70%27s_Wallpaper.JPG#/media/File:70%27s_Wallpaper.JPG
• "Flickr - ronsaunders47 - The Beatles-Sgt Pepper backdrop.". Licensed under CC BY-SA 2.0 via Wikimedia Commons - https://
commons.wikimedia.org/wiki/File:Flickr_-_ronsaunders47_-_The_Beatles-Sgt_Pepper_backdrop..jpg#/media/File:Flickr_-
_ronsaunders47_-_The_Beatles-Sgt_Pepper_backdrop..jpg
• "All you need is love graffiti Osijek" by Objavljeno - Own work. Licensed under CC BY-SA 3.0 via Wikimedia Commons - https://
commons.wikimedia.org/wiki/File:All_you_need_is_love_graffiti_Osijek.JPG#/media/File:All_you_need_is_love_graffiti_Osijek.JPG
• "Illumined Pleasure Salvador Dali" by Salvador Dalí - Own workMrArifnajafov (Photography from the original). Licensed under CC
BY-SA 3.0 via Wikimedia Commons - https://commons.wikimedia.org/wiki/File:Illumined_Pleasure_Salvador_Dali.JPG#/media/
File:Illumined_Pleasure_Salvador_Dali.JPG
• "3 Savile Row" by Original uploader was Misterweiss at en.wikipedia - Transfered from en.wikipedia Transfer was stated to be
made by User:Vinhtantran.. Licensed under Public Domain via Commons - https://commons.wikimedia.org/wiki/File:
3_Savile_Row.jpg#/media/File:3_Savile_Row.jpg
• "Paul Feyerabend 2" by Grazia Borrini-Feyerabend. Licensed under Attribution via Commons - https://commons.wikimedia.org/
wiki/File:Paul_Feyerabend_2.jpg#/media/File:Paul_Feyerabend_2.jpg
132. Images (in order used)
• "The Beatles on Green Hill in Almaty, Kazakhstan" by Ken and Nyetta - Flickr: The Beatles on
Green Hill in Almaty. Licensed under CC BY 2.0 via Commons - https://
commons.wikimedia.org/wiki/File:The_Beatles_on_Green_Hill_in_Almaty,_Kazakhstan.jpg#/
media/File:The_Beatles_on_Green_Hill_in_Almaty,_Kazakhstan.jpg
• "The Beatles in America" by United Press International, photographer unknown - This image is
available from the United States Library of Congress's Prints and Photographs division under
the digital ID cph.3c11094.This tag does not indicate the copyright status of the attached work.
• "The Beatles rooftop concert" by Source. Licensed under Fair use via Wikipedia - https://
en.wikipedia.org/wiki/File:The_Beatles_rooftop_concert.jpg#/media/
File:The_Beatles_rooftop_concert.jpg
• "Paul Feyerabend 2" by Grazia Borrini-Feyerabend. Licensed under Attribution via Commons -
https://commons.wikimedia.org/wiki/File:Paul_Feyerabend_2.jpg#/media/
File:Paul_Feyerabend_2.jpg
• Myself taken at StrangeLoop 2014 by my wife, Kelsey Harris