Hacker News new | past | comments | ask | show | jobs | submit login

Does it have inheritance and polymorphism?



From the page: "Cello isn't about Object Orientation in C".

So no. It isn't object oriented, but it does some nice-looking things with structured types.


It seems to be targeting the same market as Go or Haskell OO more than that of C++. A class in this model basically means 'definitions for a set of methods on this type', so it's more like what you understand as an interface.

For example, there's a "show" class that converts your object into a string. Any object that implements the necessary methods can thus be printed.

Another example is an iterator class. If you implement a couple of methods (move the cursor to the start, increment the cursor, see if the cursor is at the end, and get the currently pointed-at item), then you can be iterated over by a foreach loop.

Unlike Go, though, with Cello you seem to need to explicitly specify the functions used to implement each class.


>Haskell OO

Huh? Haskell is not OO by any means.


They were referring to haskell typeclasses, which is a way to dispatch to different function definitions based upon your data's type - which, if you squint, looks sort of like OO without inheritance.


Typeclasses can have sorta-inheritance, in the way that x may have to be an instance of typeclass X in order to implement typeclass Y.


Yeah. It's not clear to me that you can just do arbitrary overrides, though, like this type is the same as that one except with one function replaced. I can imagine building such a system out of Haskell primatives, though


Ah, I believe overrides are quite out the question. You already can't have two methods with the same name and a different signatures...


Of course someone has already written a paper on implementing OO on top of Haskell: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.106...


And without objects.


It is not clear to me what you think is missing from Haskell data that distinguishes it from objects


Identity, for one. Haskell is value-oriented. If two values have equal parts they are considered equal, even if they might be stored at different addresses. Barring the FFI (which is an unsafe extension), there is no way to distinguish otherwise equal values. Thus, Haskell has no concept of object identity which is necessary for a system to be object-oriented.




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: