logo       

Re: some proposals: msg#00045

Subject: Re: some proposals
On Fri, 23 May 2003, Nicolas Cannasse wrote:

> > Which means we're probably stuck with something like:
> >
> > let Int.compare x y = if (x < y) then -1 else if (x > y) then 1 else 0
> 
> Uh !
> This time Brian you're using up to TWO times polymorphic comparison !

You're right.  Need a typecast:

let Int.compare (x: int) (y: int) = if (x < y) then -1 else if (x > y) 
then 1 else 0



> I think the most easy solution is really to use the substraction, but that
> will cause the problems you showed with max_int / min_int , and doing some
> previous boundary tests before return x - y will increase the cost of it. So
> my conclusion is this is an user-specific problem (some might need max_int
> while some might not ) which should be addressed by not adding the module
> Int to the ExtLib, although it was a good idea.

Actually, handling the corner cases is a good argument, IMHO, *FOR* adding 
class Int.  This strikes me as being a common error.

> 
> About the partial_map, this can be done using a fold_left, which is more
> appropriate since you don't allocate None/Some blocks . But I think perhaps
> fold_left/right are not so easy to use in the first place, so maybe having a
> partial_map would be nice , but I would rename it to filter_map since this
> can be done using one map + one filter.

Allocating the option blocks doesn't worry me much.  I assumed that we 
wanted to a) avoid allocating an unnecessary interim list, and b) wanted 
to construct the list forwards, as opposed to doing a List.rev.  If either 
of these are relaxed, then yes, the function can be fairly easily 
implemented given existing functions.

> 
> BTW, I would prefer a more simple version of the Brian one, which does not
> need two loops :
> 
> let filter_map f l =
>     let rec loop dst = function
>         | [] -> ()
>         | h :: t ->
>             match f t with
>             | None -> loop dst t
>             | Some x ->
>                     let r = [ x ] in
>                     Obj.set_field (Obj.repr dst) 1 (Obj.repr r);
>                     loop r t
>     in
>     let dummy = [ Obj.magic () ] in
>     loop dummy l;
>     List.tl dummy
> 

I forgot about this trick.  This is a better implementation.

Brian




-------------------------------------------------------
This SF.net email is sponsored by: ObjectStore.
If flattening out C++ or Java code to make your application fit in a
relational database is painful, don't do it! Check out ObjectStore.
Now part of Progress Software. http://www.objectstore.net/sourceforge


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
science.linguis...    culture.sf.lite...    video.mplayer.c...    yellowdog.gener...    ietf.rfc822/199...    emacs.help/2002...    redhat.release....    kernel.speakup/...    java.openejb.de...    debian.devel.gt...    xfree86.newbie/...    bug-tracking.ma...    pam/2003-05/msg...    games.devel.ope...    user-groups.lin...    music.pancham/2...    network.mq.deve...    web.html.genera...    arklinux.bugs/2...    linux.ecasound/...    qnx.openqnx.dev...    org.user-groups...    file-systems.sf...    trustix.contrib...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe