
Replies inline.
On Sunday, December 13, 2015, martin
I think you're off to a good start with this insert signature:
insert :: a -> C a -> Maybe (C a) "Insert element `a` into structure `C a` and return a new structure if
Am 12/13/2015 um 11:57 PM schrieb Patrick Redmond: the insertion was successful."
This way I'd have to be explicit about what C really is, don't I? Data.Set certainly has a very explicit data structure under the hood. I was hoping to express the idea of "something that can be inserted to and removed from" without specifying how the data is actually stored.
Use a typeclass. But maybe that's a bad point to start from. At least this is where the
trouble started when I tried to implement something on top of it. I just didn't have enough "flesh" to work with.
Yes, you will have to write a concrete implementation anyway, so start with that. Make an explicit data structure, with concretely typed functions to manipulate it. When you have two of these explicit implementations, make a typeclass and provide two instances - one which delegates to each of the implementations.