Re: Another fold question

2003-11-06 Thread Thomas L. Bevan
I stand corrected On Thu, 6 Nov 2003 06:39 pm, Tomasz Zielonka wrote: > 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 t

Re: Another fold question

2003-11-06 Thread Paul Hudak
For what it's worth, I recently wrote a paper on what I call "polymorphic temporal media", of which "music" and "animation" are two examples. The basic data type is: data Media a = Prim a | Media a :+: Media a | Media a :=: Media a From this we can define a Music type:

Re: Another fold question

2003-11-06 Thread Ralf Laemmel
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

Re: Another fold question

2003-11-06 Thread Dean Herington
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

Re: Another fold question

2003-11-06 Thread Keith Wansbrough
[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

Re: Another fold question

2003-11-06 Thread Keith Wansbrough
> 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

Re: Another fold question

2003-11-06 Thread Tomasz Zielonka
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 sor

Re: Another fold question

2003-11-05 Thread Derek Elkins
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

Re: Another fold question

2003-11-05 Thread ajb
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 >

Re: Another fold question

2003-11-05 Thread Thomas L. Bevan
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

Another fold question

2003-11-05 Thread Patty Fong
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 parameter and [] by another i.e foldr (+) 0 [1,2,3] becomes 1+(2+(3+0)) I also