Abstract Storage exercise

Good evening everyone. I’m doing some final exercises in my OCaml journey and I’ve run into quite a challenger. I am very much stuck. If there’s someone willing to help with it, it would be enormously appreciated. Thank you in advance.

Here is what I need to do:
I need to represent storage using an array where each cell of the array represents a cell of storage.
Each cell of storage should be type ’a cell = Null | Cell of ’a

I should define an abstract class named “abstractStorage” that contains the following:
a field “storageSpace”, an abstract method “empty”, an abstract method “freeSpace” and an abstract method “contains”.

The value of the field “storageSpace” should be an array of type ’a cell array with the size obtained as a class parameter and representing the storage. Method empty returns true if the storage is empty and false otherwise. The method “freeSpace” returns the amount of free space in the storage. The method “contains” receives ab element of type ’a as a parameter and it returns true if that element is contained in the storage and false otherwise.

After this, I should define a subclass “queue” of the class “abstractStorage” with the following methods:
method “insert”, that receives an element of type ’a and inserts it into the storage, and a method “delete”, that deletes one element from the storage. The methods should obey the “first in first out” rule.

Similarly to this, I need to create a subclass “stack” of the class “abstractStorage”, with the same methods “insert” and “delete”, but it should obey the “first in last out” rule.

The methods for inserting and deleting should allow cyclic inserting and deleting.

And finally I need to define a class “storage” that inherits from both “queue” and “stack” and it should contain the following methods: “undo”, to return the storage to the state it was before the last action made. If it’s used a second time or more in a row it should return to the same storage state. A method “insertMany” takes as parameter a list of elements that we want to insert into the storage. A method “deleteMany” should take a bool list as a parameter and delete elements from the storage according to the value in the list one by one. Value true means following the “first in first out” rule, false means following the “first in last out” rule. And, a method “reset” that resets the storage to being empty. Applying “undo” after “reset” should keep the storage empty.

Again, thanks in advance to anyone who can help out with this, I know it’s not a small problem. I’m getting quite desperate about finishing this.

What did you try? Where are you stuck?

I haven’t tried anything. I’m stuck at the start, this is the first exercise of this kind that I see. I have an idea, but I don’t have enough experience to exactly know how to solve it.

Then, you should try to take the problem one step at a time. As a first step, you can try to define the class abstractStorage (it is really not clear what your exercise means by abstract):

class abstractStorage size = object
  val storageSpace = ...
  method empty = ...

Once you have defined this class, you can move to defining the queue class. To do so, your exercise seems to hint at using inheritance.