### Modulo-foo equivalence classes?

Just posted this to `haskell-cafe`

. I’ve probably done a horrible job at expressing myself, but gah, let’s not hoard ideas.

Watching the questions go by in #haskell, a still fuzzy but possibly pregnant idea popped up in my mind. Someone needed a nubBy function that returned an unique list modulo an arbitrary function foo. Well, in this case it wasn't arbitrary; he had a list of transposable matrices and wanted an unique list of matrices that couldn't be transposed into each other.

I'm thinking there are many cases of fooBy functions that have to be constantly rewritten, and also a lot of ugly code by having to constantly add the modulo clauses (like in modular arithmetic).

I'm inexperienced with type classes -- I've only done the simplest types and /some/ fundeps -- so I'm wondering what would be the clearest, most general way of having a Modulo-foo Eq class that could be parameterized with a function. The "transposable matrix" example shows how this could be useful for (some limited form) of data compression, but it could make some other forms of "algebraically modular" (this is not a proper term, it's me trying to get thoughts across) business rules, of which modular arithmetic is a special case.

`Uh, I've probably not expressed myself well enough; I hope I have a shot at trying to explain myself better if questions come up.
`

Filed under: Uncategorized | 2 Comments

You might be interested in the description of quotient or congruence types here:

http://www.cs.kent.ac.uk/people/staff/sjt/TTFP/ttfp.pdf

They require a undecideable dependent type system, sadly, but would be rather useful for things like this.

I can’t see a way to do this directly with type-classes though. You can parameterize them with a type, but not a function, right?

I guess you could always just do something like this:

data MatrixModuloTransposition = ModuloTransposition Matrix

instance Eq MatrixModuloTransposition where

MatrixModuloTransposition p == MatrixModuloTransposition p = p == q || p == (transpose q)