Version française
Home     About     Download     Resources     Contact us    
Browse thread
stl?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jon Harrop <jon@f...>
Subject: Re: [Caml-list] stl?
On Wednesday 04 March 2009 00:11:32 you wrote:
> On Tue, 3 Mar 2009, Jon Harrop wrote:
> > Functors give you the same capability in OCaml but they are rarely used
> > precisely because the functionality is not very useful.

Also largely because there is not enough good tutorial information available 
explaining how to leverage functors.

> I think I disagree with this.  I think functors aren't used very much in
> Ocaml because:
> 1) They're a big, scary name, and
> 2) They're slightly less efficient.
>
> The biggest difference between Haskell and Ocaml that I see is simply the
> difference between attitudes of the two communities.  The Ocaml community
> is like "Don't use functors- they disable inlining and cost you six whole
> clock cycles on a function call!  They're evil, I tell you!"

Efficiency is only important in the context of functors when abstracting very 
fast and common functions like arithmetic without defunctorizing your code. I 
don't think that is why people avoid functors in OCaml.

> Meanwhile,  
> the Haskell community is like "I used typeclasses all over my application,
> and the performance didn't completely suck- woot!  Type classes rule!"
> This is a broad generalization, and not completely accurate- but on the
> whole, the ocaml community is much more focused on (clock cycle)
> efficiency, while the Haskell community is much more focused on
> abstraction and programmer-cycle efficiency. 

I think that is a reflection of what the communities desire rather than what 
they already have. OCaml is already fast (particularly on amd64) but OCamlers 
always want even better performance. Haskell's development experience is a 
real sore point and they want to address that. However, I would also say that 
both communities are moving very slowly toward these goals.

> The type classes comparison isn't even an analogy- it's a precise
> relationship. Anywhere you might be thinking, in Ocaml, "this would be a 
> nice place to use a type class", use a functor.  You want operator
> overloading in Ocaml?  You got it: use a functor.

Functors do not facilitate operator overloading. You still end up with a 
combinatorial explosion in the number of operator names.

> If this causes you a 
> knee jerk reaction about performance, ask yourself this: do you know how
> type classes are implemented in Haskell, and what their performance hit
> there is?  Now, imagine programming haskell where typeclasses are only
> used in a very places- Ord, Eq, Monad.  No Num.  No Monoid.  No Show.
> That's Ocaml.  Not that it has to be.

I don't follow your breakdown. OCaml does not have Ord and Eq, it only has a 
hack for structural equality. Same for Show. Few people care about Monad, Num 
and Monoid.

However, that is trivial to fix with run-time type information that can convey 
per-type functions. Both F# and my HLVM already do that.

> Having actually used Haskell for a while, I think I actually like functors
> better than type classes.  But that's a rant for a different venue.  The
> big difference is that Haskell programmers use type classes, and the Ocaml
> programmers don't use Functors (very often, if at all).

There are some very good examples of functors out there, like ocamlgraph.

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