<div dir="ltr"><div><div>Tidal [1] defines these data types:</div><div> </div><div> type Time = Rational</div><div> type Arc = (Time, Time)</div><div> </div><div>I want to write a function "splitMultiCycArc" which divides an Arc into mostly-integer segments, so that, for instance,</div><div> </div><div> splitMultiCycArc (0,1) = [(0,1)]</div><div> splitMultiCycArc (0,2) = [(0,1),(1,2)]</div><div> splitMultiCycArc (0,3) = [(0,1),(1,2),(2,3)]</div><div> splitMultiCycArc (1%2,2) = [(1%2,1),(1,2)]</div><div> splitMultiCycArc (1,5%2) = [(1,2),(2,5%2)]</div><div><br></div><div>I thought I had solved the problem with this code:</div><div><br></div><div> splitMultiCycArc:: Arc -> [Arc]</div><div> splitMultiCycArc (a,b) = let ceiling_ish = floor a + 1 in</div><div> if b <= a then [] </div><div> else if b <= ceiling_ish then [(a,b)]</div><div> else (a,ceiling_ish) : splitMultiCycArc (ceiling_ish,b)</div><div> </div><div>When I try to load that, I get this single error:</div><div><br></div><div> > :reload</div><div> [12 of 13] Compiling Sound.Tidal.JBB ( Sound/Tidal/JBB.hs, interpreted )</div><div> </div><div> Sound/Tidal/JBB.hs:16:44:</div><div> No instance for (Integral Time) arising from a use of ‘floor’</div><div> In the first argument of ‘(+)’, namely ‘floor a’</div><div> In the expression: floor a + 1</div><div> In an equation for ‘ceiling_ish’: ceiling_ish = floor a + 1</div><div> Failed, modules loaded: Sound.Tidal.Strategies, Sound.Tidal.Dirt, Sound.Tidal.Pattern, Sound.Tidal.Stream, Sound.Tidal.Parse, Sound.Tidal.Tempo, Sound.Tidal.Time, Sound.Tidal.Utils, Sound.Tidal.SuperCollider, Sound.Tidal.Params, Sound.Tidal.Transition.</div><div> > </div><div> </div><div>And yet under other conditions, "floor" is perfectly happy operating on a Time value:</div><div><br></div><div> > let a = (1%2,1) :: Arc</div><div> > floor (fst a) + 1</div><div> 1</div><div> > </div><div><br></div><div>[1] <a href="https://hackage.haskell.org/package/tidal">https://hackage.haskell.org/package/tidal</a></div></div><div><br></div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">Jeffrey Benjamin Brown</div></div>
</div>