caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: [Caml-list] Sorting
@ 2001-11-02 15:10 Krishnaswami, Neel
  0 siblings, 0 replies; 6+ messages in thread
From: Krishnaswami, Neel @ 2001-11-02 15:10 UTC (permalink / raw)
  To: 'Marcin 'Qrczak' Kowalczyk', caml-list

Marcin 'Qrczak' Kowalczyk [mailto:qrczak@knm.org.pl] wrote:
> 
> What are advantages and disadvantages in parametrizing either by '<'
> or by the 3-way comparison?

If comparisons are very expensive -- for instance, if the elements
are long strings or large sets -- then it makes for faster execution
to use a three-way comparison. On the average you will do two-thirds
as many comparisons while sorting with a three-way comparison. 

I find this irritating becuase it just *feels* nicer to pass a 
function of type elt -> elt -> bool to a sorting function. It's
closer to how sorting is taught, and hence to my mental model. :)

--
Neel Krishnaswami
neelk@cswcasa.com
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 6+ messages in thread
* Re:  [Caml-list] Sorting
@ 2001-10-31 13:42 Damien Doligez
  2001-11-02 14:38 ` Pierre Weis
  0 siblings, 1 reply; 6+ messages in thread
From: Damien Doligez @ 2001-10-31 13:42 UTC (permalink / raw)
  To: caml-list

>From: "Marcin 'Qrczak' Kowalczyk" <qrczak@knm.org.pl>

>Sort.array : order:('a -> 'a -> bool) -> 'a array -> unit
>Sort.list  : order:('a -> 'a -> bool) -> 'a list -> 'a list

Old functions, obsolescent.

>Array.sort : cmp:('a -> 'a -> int) -> 'a array -> unit
>List.sort  : cmp:('a -> 'a -> int) -> 'a list -> 'a list

New functions.


>What are advantages and disadvantages in parametrizing either by '<'
>or by the 3-way comparison?

It's better because it is more modern :-)

Seriously, the 3-way comparison is more consistent with the
definition of Map.OrderedType.

-- Damien
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 6+ messages in thread
* [Caml-list] Sorting
@ 2001-10-31  7:54 Marcin 'Qrczak' Kowalczyk
  2001-11-05  9:22 ` Xavier Leroy
  0 siblings, 1 reply; 6+ messages in thread
From: Marcin 'Qrczak' Kowalczyk @ 2001-10-31  7:54 UTC (permalink / raw)
  To: caml-list

Sort.array : order:('a -> 'a -> bool) -> 'a array -> unit
Sort.list  : order:('a -> 'a -> bool) -> 'a list -> 'a list
Array.sort : cmp:('a -> 'a -> int) -> 'a array -> unit
List.sort  : cmp:('a -> 'a -> int) -> 'a list -> 'a list

What are advantages and disadvantages in parametrizing either by '<'
or by the 3-way comparison?

-- 
 __("<  Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^
QRCZAK

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2001-11-05 12:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-02 15:10 [Caml-list] Sorting Krishnaswami, Neel
  -- strict thread matches above, loose matches on Subject: below --
2001-10-31 13:42 Damien Doligez
2001-11-02 14:38 ` Pierre Weis
2001-10-31  7:54 Marcin 'Qrczak' Kowalczyk
2001-11-05  9:22 ` Xavier Leroy
2001-11-05 12:26   ` jeanmarc.eber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).