[Haskell-cafe] I miss OO
Gregg Reynolds
dev at mobileink.com
Thu Nov 26 05:07:32 EST 2009
On Wed, Nov 25, 2009 at 2:51 PM, Michael Mossey <mpm at alumni.caltech.edu> wrote:
>
> So if I have objects/data note1, cursor1, and staff1,
>
> Python:
> note1.time()
> cursor1.time()
> staff1.time()
>
> Haskell needs something like
> note_time note1
> cursor_time cursor1
> staff_time staff1
Modeling musical stuff could provide an excellent illustration of the
difference between OO and the Haskell way; it's the difference between
metaphysical engineering and constructive mathematics. Think algebra.
Haskell isn't just about types, its about algebraic types: structures
and operations (signatures). So instead of asking ``what kind of
object is a note?'', ask ``what is the algebra of notes?'' And not
``what kind of mathematical object is a note?'' but ``what kind of
alegebraic formula describes (constructs) a note?'' You get a type
constructor and some data constructors, which are essentially
algebraic formulae that allow you to construct (i.e. refer to,
describe) note values using values of other types. Then you add some
operators, which are defined using those constructive formulae
(deconstruction via pattern matching.) Type classing allows you to
use the same names for operations on different algebras. Etc.
Then ``how do I access the time contained in this note?" becomes ``how
do I construct a formula describing the time value used to construct
this note?''. I.e. it's all about the algebraic notations rather than
the metaphysics of ``objects'', and Haskell gives you a variety of
ways to do this, as other responses in the thread have pointed out.
-gregg
More information about the Haskell-Cafe
mailing list