I have a few modules providing functions working on a datatype called
Pattern, and am making a new similar-but-different datatype called
Sequence. Patterns are like signals - a function from time to elements. Sequences are like lists of elements. But they’re both different representations for (musical) patterns.
The thing is though that I’d like to use the same function names for both datatypes, like
rev for reversing them
fast for speeding them up, etc. This seems like a job for typeclasses/instances.
Here’s our current attempt:
Importing the Pattern modules (Pattern, Core and UI) and the Sequence module (just Sequence), hiding all the common functions which are then combined using a typeclass called
It’s working but as you can see, involves a lot of qualification and hiding which I think is going to become impractical as we add more common functions.
I’m struggling to find a better way - maybe renaming all the instance-specific functions in terms of their type (
seqFast etc) which makes some sense but is a little bit messy.
Or perhaps I’m going about this the wrong way. Any advice much appreciated!