[Haskell-cafe] Need ideas how to model the lack of something
plredmond at gmail.com
Mon Dec 14 07:21:07 UTC 2015
On Sunday, December 13, 2015, martin <martin.drautzburg at web.de> wrote:
> Am 12/13/2015 um 11:57 PM schrieb Patrick Redmond:
> > 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
> 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
When you have two of these explicit implementations, make a typeclass and
provide two instances - one which delegates to each of the implementations.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe