Another fold question

Keith Wansbrough Keith.Wansbrough at cl.cam.ac.uk
Thu Nov 6 10:22:52 EST 2003


[replying to self, oops]

> >         getNotes n@(Note _ _ _) = [n]
[..]
> But of course every function of this form *is a fold* and can be written as such.

Oops, I didn't look closely enough at this line.  As written, this
*isn't* a fold because it examines the item (Note _ _ _ :: Music)
directly rather than just looking at its arguments.  But (a) it's
academic in this case - since none of the arguments are recursive, you
can just write

  getNotes (Note p o d) = [Note p o d]

and become a fold again; and (b) you don't need to return the note to
count it, you need only to add one to a counter.

--KW 8-)



More information about the Haskell-Cafe mailing list