11 ms·
"An object is a first-class, dynamically dispatched behavior. A behavior is a collection of named operations that can be invoked by clients where the operations
by dllthomas 12y ago
"An object is a first-class, dynamically dispatched behavior. A behavior is a collection of named operations that can be invoked by clients where the operations may share additional hidden details. Dynamic dispatch means that different objects can implement the same operation name(s) in different ways, so the specific operation to be invoked must come from the object identified in the client's request. First class means that objects have the same capabilities as other kinds of values, including being passed to operations or returned as the result of an operation.
A language or system is object oriented if it supports the dynamic creation and use of objects. Support means that objects are easy to define and use. It is possible to encode objects in C or Haskell, but an encoding is not support."
I'm perfectly happy to not call Haskell "object oriented", but I fail to see how the "record of closures" pattern fails to meet all of his criteria including ease of creation and use.
Edited to add: To be clear, I fully agree with him that typeclasses have nothing to do with OO in Haskell, by his definition of OO.
- abecedarius 12y agoI'd agree that Haskell supports object-oriented programming: I've written a small program or two that way. Saying a language is object-oriented carries a connotation though that it's meant for that style. His definition does not fit that connotation.
- gamegoblin 12y agoI'm reminded of "Closures and Objects are equivalent" (http://c2.com/cgi/wiki?ClosuresAndObjectsAreEquivalent http://c2.com/cgi/wiki?ClosuresAndObjectsAreEquivalent) That being said, you can easily create a data type in Haskell that contains a bunch of "methods" that live in the IO monad and mutate other bits of data the object contains that also live in the IO monad, but it's a bit of a forced paradigm.
- dllthomas 12y ago'I'm reminded of "Closures and Objects are equivalent"' Sure, though to be clear I'm not taking any position on that question above. I just think that the pattern solidly fulfills all of the criteria he gave, and it's not a terrifically obscure one. 'That being said, you can easily create a data type in Haskell that contains a bunch of "methods" that live in the IO monad and mutate other bits of data the object contains that also live in the IO monad, but it's a bit of a forced paradigm.' I think what you're getting at here is that persistent identity and mutable state are necessary parts of IO? It's clear that they're often assumed to be; I've encountered the question before and I lean weakly "no", although not with confidence. More importantly, they are explicitly disclaimed as being an inherent part of IO as defined in the article, so were not what I was speaking to. I agree that an IO-backed message passing object framework 1) could be built in Haskell and 2) would not be a natural fit.
- dllthomas 12y ago... necessary parts of OO.