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

Sumit Sahrawat, Maths & Computing, IIT (BHU) sumit.sahrawat.apm13 at iitbhu.ac.in
Sun Dec 13 20:49:11 UTC 2015

You can implement a structure which hides a max length and a length inside
it, whose record accessors are not exported.

Also, rather than thinking of insert and remove as operations *inside* the
structure, think of them separately. Define just the data structure first,
and then define the operations afterwards. This separates the interface and
implementation, allowing you to change the structure without changing the

On 14 December 2015 at 01:45, martin <martin.drautzburg at web.de> wrote:

> 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.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

Sumit Sahrawat,

Junior - Mathematics and Computing,
Indian Institute of Technology - BHU,
Varanasi, India
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20151214/62c0193d/attachment.html>

More information about the Haskell-Cafe mailing list