[Haskell-beginners] Re: making translation from imperative code
apfelmus at quantentunnel.de
Tue Mar 31 22:20:28 EDT 2009
Michael Mossey wrote:
> I'm translating a Python program into Haskell, and running into a
> problem---a type of code where I don't know how to make the conceptual
> The Python code does a graphical layout of a music score. There is a
> loop in which it add items (chords, symbols, text, etc.) one at a time,
> moving to the right, until it reaches the end of the line. So in typical
> imperative code, we have a bunch of loop state, such as
> - xpos of last chord or symbol placed
> - time of last chord or symbol placed
> - several StaffData objects, each containing the symbols that went
> on that particular staff
> - a cache of miscellaneous information about each symbol for later
> So imperative code is pretty simple: loop, and each time update the
> state. Much of this state consists of lists to which symbols are added
> once per loop.
Can you elaborate on what exactly the algorithm is doing? Does it just
emit notes/chords/symbols at given positions or does it also try to
arrange them nicely? And most importantly, "where" does it emit them to,
i.e. what's the resulting data structure?
So far, the problem looks like a basic fold to me.
More information about the Beginners