[Haskell-beginners] Why does floor not consider its argument an Integral?
Jeffrey Brown
jeffbrown.the at gmail.com
Sun Nov 8 06:14:58 UTC 2015
Tidal [1] defines these data types:
type Time = Rational
type Arc = (Time, Time)
I want to write a function "splitMultiCycArc" which divides an Arc into
mostly-integer segments, so that, for instance,
splitMultiCycArc (0,1) = [(0,1)]
splitMultiCycArc (0,2) = [(0,1),(1,2)]
splitMultiCycArc (0,3) = [(0,1),(1,2),(2,3)]
splitMultiCycArc (1%2,2) = [(1%2,1),(1,2)]
splitMultiCycArc (1,5%2) = [(1,2),(2,5%2)]
I thought I had solved the problem with this code:
splitMultiCycArc:: Arc -> [Arc]
splitMultiCycArc (a,b) = let ceiling_ish = floor a + 1 in
if b <= a then []
else if b <= ceiling_ish then [(a,b)]
else (a,ceiling_ish) : splitMultiCycArc (ceiling_ish,b)
When I try to load that, I get this single error:
> :reload
[12 of 13] Compiling Sound.Tidal.JBB ( Sound/Tidal/JBB.hs, interpreted
)
Sound/Tidal/JBB.hs:16:44:
No instance for (Integral Time) arising from a use of ‘floor’
In the first argument of ‘(+)’, namely ‘floor a’
In the expression: floor a + 1
In an equation for ‘ceiling_ish’: ceiling_ish = floor a + 1
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.
>
And yet under other conditions, "floor" is perfectly happy operating on a
Time value:
> let a = (1%2,1) :: Arc
> floor (fst a) + 1
1
>
[1] https://hackage.haskell.org/package/tidal
--
Jeffrey Benjamin Brown
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151107/8143a3d8/attachment.html>
More information about the Beginners
mailing list