On Saturday 17 January 2009 21:22:19 Kuba Ober wrote:
> On Jan 17, 2009, at 11:59 AM, Jon Harrop wrote:
> > On Saturday 17 January 2009 14:35:22 Kuba Ober wrote:
> >> I wonder how such a hierarchy would be implemented in a natural way
> >> in OCaml?
> >
> > Assuming you stick with accepted wisdom, you would mimic the same
> > effects
> > using OCaml's object system, just as LablGTK does. However, you have
> > picked
> > the only pedagogical OO example: GUI widgets.
>
> Perhaps that's where OO paradigm really shines. I'm very much against
> shoehorning everything into it, of course.

We've wrapped part of WPF in a functional shim for our F# for Visualization 
product and, even though it was originally intended for internal use only, 
our customers are loving using it themselves because it is vastly simpler and 
less error prone than trying to use WPF's own heavily-imperative but entirely 
thread unsafe OOP-based API directly.

Also, specifying callbacks and event handlers as first-class functions is 
obviously preferable to an OOP-based workaround.

> > In contrast, metaprogramming is the pedagogical example for algebraic
> > datatypes. There is almost no need for users to extend the abstract
> > syntax
> > tree but there is huge value in being able to rewrite expressions
> > using
> > pattern matching. There is an idiomatic OOP solution to this problem
> > that
> > involves visitor patterns and so forth but it is comparatively
> > verbose,
> > obfuscated and unmaintainable.
>
> You've got me there -- I never liked the visitor pattern, and by
> extension the event-based XML parsers written in C-like languages.

Oh yes. Java is utterly intolerable in that respect. I cannot believe how 
popular it became despite that...

Parallelism and concurrency are other examples where OOP sucks.

Cilk and Microsoft's TPL are the gold standards for parallel programming right 
now and both are build around concurrent work stealing queues of functions 
waiting to be applied. This works best for divide and conquer algorithms 
which, in turn, lend themselves to recursive functions. The reason being that 
older functions on a queue are more likely to be parent functions that will 
spawn many offspring, so when an idle core steals from the back of another 
core's queue it is likely to steal a parent function that will keep it busy 
for some time to come.

F#'s asynchronous workflows use monadic style to make concurrent programming 
easier.

Incidentally, Cilk looks like the ideal tool to write a parallel GC...

-- 
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to