johnklee / fpu

Functional programming utility
MIT License
4 stars 4 forks source link

Clarification of general concept of classes List, Nil, and Cons #44

Open wkCircle opened 1 year ago

wkCircle commented 1 year ago

The abstract class List contains naturally many abstract functions and is thus intended to be inherited with those abstracts being properly overridden.

Currently they are two subclasses that inherit List, the Nil class and the Cons class. I guess the Nil class is intended to represent the concept of Null, yet I don't know what Cons does. Besides, I have found that List.foldLeft is defined while List.foldRight is abstracted, which is then defined in Cons. This confuses me because I don't know if foldRight should be implemented in Cons, or in the earlier stage List. For another example, List.append is also abstracted, but I don't know if it should be the case or not. Because list naturally has the append method and thus no need to wait till the subclass to implement it? Or am I getting confused due to the name List?

Generally speaking, lacking of the knowledge of what these classes are and what their relationship is, it is difficult to decide when (or at which class) to realize an abstract method.

If would be very helpful if @johnklee can help clarify this, or recommend a book/resource. Many thanks in advance.