Follow

something rearranged in my brain when i saw some instructional haskell resource make the observation that fold is just replacing the constructors of a data type with a function that purrocesses them. it’s just the canonical destructor fur an inductively defined type

(foldr f z '(1 2 3)) transfurms (cons 1 (cons 2 (cons 3 '()))) into (f 1 (f 2 (f 3 z)))

a list is a type with constructors cons and nil. fold takes handlers fur both of those (nil being handled by just purroducing any arbitrary value). it recurses because the second argument to cons is a list

Sign in to participate in the conversation
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.