[Haskell-cafe] How to abstract away set representation

Rogan Creswick creswick at gmail.com
Tue Mar 10 13:45:39 UTC 2015

On Mon, Mar 9, 2015 at 1:30 PM, martin <martin.drautzburg at web.de> wrote:
> How would I use this? If I have a listProf and I want to perform pCount, must I then choose the pCount from listProf?
> Something like
>         pCount listProf aProfile
> But then my code knows that I am using a list representation, which is the thing I wanted to avoid.
> I tried to pair the ops with the representation, but this also got me into trouble, because when I e.g. do a pAdd then
> it gets strange when the two operands do not use the same Ops.

You could possibly hide the details by using GADTs, adding a new data
constructor for each underlying type (which could also be abstracted
as in the suggestion from Tom), but you still have to deal with an
unavoidable issue -- you'll have to encode how to add collections of
disparate types at some point.  E.g., how do you add a `Prof Int`
that's backed by a `Set a` to a `Prof Int` backed by a `[Int]` ? (at
least I think that's unavoidable -- you may be able to solve it with a
type class that moves the combination logic elsewhere.)


More information about the Haskell-Cafe mailing list