3 ms·
> OO like in Haskell Please explain. Are you referring to type classes?
by adwn 12y ago
> OO like in Haskell
Please explain. Are you referring to type classes?
- pjmlp 12y agoYes. Type classes is a way of doing polymorphism in Haskell, the central point of OO.
- adwn 12y agoI thought the central point of OOP was to encapsulate functions ("methods") and the data ("objects") they operate on, thereby providing a way to structure code? That's why it's called "Object Oriented Programming" and not "Polymorphism X Y". Wikipedia at least seems to agree with me.
- pjmlp 12y agoThat is only in the case of OOP as introduced by Smalltalk. For example, OOP with multi-methods, does not imply such encapsulation.
- kasey_junk 12y agoI think one problem that people have when they are talking about object oriented (or FP for that matter), is that there isn't a clear definition around what it means. Most developers agree that it is some mix of encapsulation, polymorphism and inheritance. There is a lot of disagreement about which of those is more important. For me polymorphism is the most important, encapsulation is useful sometimes, and inheritance might be a negative attribute. For you encapsulation.
- agumonkey 12y agoI had that revelation at my college Lab, teacher discussing why OOP was such a beautiful thing, none of them could agree on definition of OOP nor the qualities. FP is smaller and stricter, it's almost formally defined (you have denotational semantics for FP VM for what it's worth).
- kyllo 12y agoOO is more general than that, it's just a general paradigm for code reuse. Polymorphism is one of many forms of code reuse (allowing functions to accept multiple type signatures). I wouldn't call it the "central point" because polymorphism can be done without OOP, and OOP can be done without polymorphism.
- kaonashi 12y agoWhat you're saying is that traditional OO conflates polymorphism with encapsulation and inheritance, creating one big complexity murder-death-ball; whereas Haskell lets you have these things a-la carte, so you can deploy them as needed.
- pjmlp 12y agoIt is central. Without polymorphism you don't have a way to abstract algorithms over types. So you just get ADTs as introduced by Mesa/Modula-2.
- kyllo 12y agoYou can do OOP with only ad-hoc polymorphism, which is just method overloading, which is what Java and C++ do. Actual parametric polymorphism isn't necessary for OOP, and there are non-OOP languages that have it (e.g. SML has polymorphism but does not have objects). So, polymorphism and object-orientation are orthogonal concerns. OOP is about encapsulation, inheritance, and modules that couple mutable state (attributes) and behavior (methods).
- agumonkey 12y agoFor the curious, Ocaml mixes both, its object model is parametric (see: http://caml.inria.fr/pub/docs/u3-ocaml/ocaml-objects.html http://caml.inria.fr/pub/docs/u3-ocaml/ocaml-objects.html)
- pjmlp 12y ago> You can do OOP with only ad-hoc polymorphism... Which is still polymorphism. I purposely did not enumerate all CS forms of polymorphism, but can get more detailed if you will.