Saturday, 10 August 2013

Why is there a type class Measured for Data.FingerTree instead of just a function?

Why is there a type class Measured for Data.FingerTree instead of just a
function?

I don't understand why FingerTree is implemented with the type class
Measured.
I'm trying to implement a sequence of monoid that have the default measure
the same as the monoid, so I wrote the following.
instance Monoid a => Measured (Sum Int, a) a where
measure x = (Sum 1, x)
Of course, since FingerTree itself is a Measured, this is impossible as we
will get type class overlap.
At what point was abstracting this single function into a type class make
sense? Why can't we just define FingerTree so we can feed a measure
function to the constructor?
It would also be nice to know if there are ways to overcome this problem.
I could just define a new instance for my particular use case each time,
but maybe there is a better way.

No comments:

Post a Comment