On Thu, Nov 06, 2003 at 03:41:32PM +1100, Thomas L. Bevan wrote:
patty,
what you have written is not a fold. A fold operates over a list. There is no
list in your code, only some sort of tree structure.
I think you are wrong. Folds are not restricted to lists and lists are
also some sort of
I know this doesn't answer your question, but for this example, it might
be easier to use some kind of iterator. In this example:
getNotes :: Music - [Music]
getNotes n@(Note _ _ _) = [n]
getNotes (PlayerPar m1 m2) = getNotes m1 ++ getNotes m2
-- etc etc
[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
At 4:27 AM + 2003/11/06, Patty Fong wrote:
data Music
= Note Pitch Octave Duration
| Silence Duration
| PlayerPar Music Music
| PlayerSeq Music Music
| Tempo (Ratio Int) Music
data Pitch = Cf | C | Cs
type Octave = Int
type Duration = Ratio Int
foldMusic
Continuing Keith's self-reply ...
the Music type involves types
other than Music; so it is fair to say that
ultimately you would need generalised folds
extended to the case of *systems* of datatypes
(cf. Dealing with large bananas). Imagine
for example getPitches :: Music - [Pitch].
Even if a
patty,
what you have written is not a fold. A fold operates over a list. There is no
list in your code, only some sort of tree structure.
foldMusic :: (Pitch - Octave - Duration - a)
- (Duration - a)
- (a - a - a)
- (a - a - a)
- (Ratio Int - a - a)
- Music
G'day all.
Quoting Patty Fong [EMAIL PROTECTED]:
I also understand how to write my own fold function. What i don't understand
quite is how to use them. given this data type and this fold function i
wrote:
data Music
= Note Pitch Octave Duration
| Silence Duration
|
On Thu, 06 Nov 2003 04:27:31 +
Patty Fong [EMAIL PROTECTED] wrote:
Having struglled over this for the better part of a day and only
becoming more frustrated the more i try to understand it, i once again
seek help :)
I understand how basic folds work, i.e foldr replaces (:) with some