<div dir="ltr">You can implement a structure which hides a max length and a length inside it, whose record accessors are not exported.<div><br></div><div>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 API.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 14 December 2015 at 01:45, martin <span dir="ltr"><<a href="mailto:martin.drautzburg@web.de" target="_blank">martin.drautzburg@web.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello all,<br>
<br>
here is a problem where I did not manage to find a suitable abstraction. The main idea goes like this:<br>
<br>
a List (and many other containers) can be seen as something containing "stuff". There is a function (:) that<br>
unconditionally adds an element to the container and returns a new container<br>
<br>
Now suppose the container has the possiblility to refuse having another element added to it, e.g. because it has only<br>
limited "space". In that case the corresponding function would have a signature of insert :: a -> C a -> Maybe (C a). If<br>
an item can successfully be added, then the returned container will be less space avaiable.<br>
<br>
I'd like stuff and space to be symmetrical (maybe there lies the first flaw, because I can enumerate the elements, but I<br>
cannot enumerate the space). A symmetry like electrones and holes.<br>
<br>
I started like this<br>
<br>
data C a = C {<br>
insert :: a -> Maybe (C a),<br>
remove :: Maybe (a, C a)<br>
}<br>
<br>
but I could not implement anything sensible on top of this.<br>
<br>
I'd be happy to hear any comments on this, including loud thinking and random ramblings.<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div style="font-size:12.8px"><span style="font-size:12.8px">Sumit Sahrawat,</span></div><div style="font-size:12.8px"><span style="font-size:12.8px"><br></span></div><div style="font-size:12.8px"><span style="font-size:12.8px">Junior - Mathematics and Computing</span><span style="font-size:12.8px">,</span><br></div><div dir="ltr" style="font-size:12.8px"><div>Indian Institute of Technology - BHU,</div><div>Varanasi, India</div></div></div></div></div></div></div></div>
</div>