[Haskell-cafe] How to abstract away set representation

martin martin.drautzburg at web.de
Mon Mar 9 20:30:27 UTC 2015

Am 03/08/2015 um 10:05 PM schrieb Tom Ellis:

>> If you really want the type parameter to be exposed you can use
>>     data ProfOps prof = P {
>>         pCount  :: forall a. prof a -> Count
>>         pFilter :: forall a. (a -> Bool) -> prof a -> prof a
>>         pAdd    :: forall a. prof a -> prof a
>>     }
> Actually the above is the only version which works because pFilter mentions
> a.  In that case you need the following package
>     listProf :: ProfOps []
>     listProf = P {
>       pCount  = length,
>       pFilter = filter,
>       pAdd    = (++)
>     }

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.

More information about the Haskell-Cafe mailing list