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
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:
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
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
[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
> 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
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
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
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
>
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
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
11 matches
Mail list logo