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
>       | PlayerPar Music Music
>       | PlayerSeq Music Music
>       | Tempo (Ratio Int) Music
> data Pitch = Cf | C | Cs
> type Octave = Int
> type Duration = Ratio Int

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

        count_notes = length . getNotes

See http://haskell.org/hawiki/IterationPattern for some ideas.
 
Cheers,
Andrew Bromage
_______________________________________________
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to