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 22:42:15 Yoann Padioleau wrote:
> Brian Hurt <bhurt@spnz.org> writes:
> > On Wed, 4 Mar 2009, Yoann Padioleau wrote:
> >> Again, just imagine one second that 'a list were not present in OCaml,
> >> and that the only way you had to make a list would be to use
> >> a functorized interface of a List module. Would you like that ?
> >> (that's what we are forced to do when using Map and that's why
> >> I always use Hashtbl instead).
> >
> > Humorously enough, I'm doing exactly this.  In a bunch of code I'm
> > playing with, I've implemented an NeList module- nothing fancy, just a
> > few dozen lines of code and the basic list operations, only the lists
> > can not be empty.  They always have to contain at least one element.
> >
> > But seriously, you hate functors that much?
>
> With a passion :) I don't like functors for generic data structures
> such as Map.
>
> If you have some code that you want to parametrize over multiple types,
> and each of this type has some complex constraints, then I like functors.

Exactly.

> But when the only constraints on your type is that you want a Ord, or a Eq
> (or a Show), then I think functors are overkill,

Yes.

> and I am fine with the default Pervasives.compare

No, that is really error prone.

You want "compare" to run-time dispatch to the appropriate comparison function 
(e.g. Set.compare) when it hits a reference type.

> In a similar way, you have some complex code polymorphic in a 'a
> and at some point, deep inside a call chain, you want to print
> some debugging information about this tiny 'a,  so you really
> want to do a      generic_print x, but you can not.
> Or if you want to do that you have to turn that into a functor
> taking a T where the T is contrained to have a 'print' method/function.
> With haskell you just write 'show x', and haskell inference will
> do the work to add the Show a =>. So right now in OCaml
> I tend to use the Dumper module of Richard Jones. When I can
> avoid functors, I do so.

Right. Generic printing in HLVM is nice. :-)

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