<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div class="h5"><br></div></div>
That&#39;s what I want to do. I&#39;m asking about a good way to write the algorithm that traverses the notes and reconstructs the document with the correct duration in each note. </blockquote><div><br></div><div>why isn&#39;t this as simple as foldr&#39;ing something like this over the xml notes (assuming monophony and that they are listed in order of start time)?</div>
<div><br></div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;, monospace; ">readNote xmlNote nl | null nl      = mkNote : []</span></div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;, monospace; ">                    | (</span><span class="Apple-style-span" style="font-family: &#39;courier new&#39;, monospace; ">n:ns) &lt;- nl = </span></div>
<div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;, monospace; "> if not $ followedByTie xmlNote then mkNote : nl</span></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">                                else n {dur = dur n `durPlus` xdur} : ns</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"> where xdur   = </font><span class="Apple-style-span" style="font-family: &#39;courier new&#39;, monospace; ">getDur xmlNote</span></div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;, monospace; ">       mkNote = </span><span class="Apple-style-span" style="font-family: &#39;courier new&#39;, monospace; ">Note {dur = xdur}</span></div>
<div><br></div><div>durPlus would be fun to implement for the NoteDur class...  is polyphony the crux of the problem?  if so, then the simple list data structure shown here won&#39;t work, you need a graph, as mentioned by serguey.  but the idea is the same.</div>
<div>  </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Actually, I don&#39;t want to lose information about the original form of the document, so I have separate fields for the duration of the graphical single note, and the duration of the tied chain.<br>
</blockquote><div><br></div><div>i think that&#39;s asking for trouble -- i would recompute the ties myself -- it&#39;s a matter of engraving style what the rules about ties are anyway.  if you insist on being faithful to the input&#39;s ties, i would add some sort of reference to the note tiedTo (and maybe the note tiedFrom) to the Note record, but that means giving each note some sort of name or key or index.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Actually, it is better to speak of the end time than the duration, because what units do you put duration in? Beats? </blockquote><div><br></div><div>see my EDSL.  duration is in units like <font class="Apple-style-span" face="&#39;courier new&#39;, monospace">(Dotted $ Triplet Half)</font>, which is the natural musician&#39;s (and engraver&#39;s) unit.  the time signature specifies the number of beats per quarter.  if you store end location instead, you&#39;ll need to have some <font class="Apple-style-span" face="&#39;courier new&#39;, monospace">(start -&gt; end -&gt; duration)</font> which has to know how to cross measure boundaries, which is unnecessarily complex, especially with changing time signatures.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">The time signature could be changing measure to measure. </blockquote><div><br></div><div>yeah i don&#39;t deal with changing time signatures or tempos.  but it&#39;s easy to see how to handle time signature changes, since that can only change at a measure boundary:</div>
<div><br></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">data Measure = Measure {</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">    notes :: [Note]</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  , timeSig :: TimeSig</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  }</font></div><div><br></div><div>
tempo changes are trickier (esp if allowed mid-measure?), but only matters if you need to resolve onsets/durations/offsets to real-world time.  still looks straightforward...</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

I use Rational so there is no worry about precision of Floats.<br></blockquote><div><br></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">forall x. (Real x, Fractional x) =&gt; x</font> if you&#39;re picky.  Rationals are not locally compact and are not a complete metric -- almost all Reals are irrational.  :)</div>
<div><br></div><div>-e</div></div>