[Haskell-cafe] Need ideas how to model the lack of something

martin martin.drautzburg at web.de
Sun Dec 13 20:15:59 UTC 2015

Hello all,

here is a problem where I did not manage to find a suitable abstraction. The main idea goes like this:

a List (and many other containers) can be seen as something containing "stuff". There is a function (:) that
unconditionally adds an element to the container and returns a new container

Now suppose the container has the possiblility to refuse having another element added to it, e.g. because it has only
limited "space". In that case the corresponding function would have a signature of insert :: a -> C a -> Maybe (C a). If
an item can successfully be added, then the returned container will be less space avaiable.

I'd like stuff and space to be symmetrical (maybe there lies the first flaw, because I can enumerate the elements, but I
cannot enumerate the space). A symmetry like electrones and holes.

I started like this

data C a = C {
            insert :: a -> Maybe (C a),
            remove :: Maybe (a, C a)

but I could not implement anything sensible on top of this.

I'd be happy to hear any comments on this, including loud thinking and random ramblings.

More information about the Haskell-Cafe mailing list