caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] List.sort
@ 2002-06-19  8:54 Johann Spies
  2002-06-19 15:14 ` Stefano Zacchiroli
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Johann Spies @ 2002-06-19  8:54 UTC (permalink / raw)
  To: caml-list

I apologise for asking a newbie question on this list, but the
beginners-list seems to have a problem.  After 24 hours my message
did not appear on the list and there was actually no activity the last
few days.

I am trying to figure out how to use List.sort.

According to the manual the Persvasives.compare function is suitable
to use with List.sort.  I can't figure out how to use it:
----------------------------
# k;;
- : int list = [3; 2; 1]
# List.sort (compare 1 2) k;;
This expression has type int but is here used with type 'a -> 'a ->
int
# List.sort (+) k;;
- : int list = [1; 2; 3]
# a;;
- : char list = ['d'; 'b'; 'g']
# List.sort (+) a;;
This expression has type char list but is here used with type int list
# List.sort (compare 'a' 'b') a;;
This expression has type int but is here used with type 'a -> 'a ->
int
# compare 'a' 'b';;
- : int = -1
#
---------------------
What is confusing to me is that the manual says:

"Sort a list in increasing order according to a comparison
function. The comparison function must return 0 if it arguments
compare as equal, a positive integer if the first is greater, and a
negative integer if the first is smaller. For example, the compare
function is a suitable comparison function. " 

I could not find a single example on how to use this function in the
manual.  Can somebody show me how to use it please?

Johann
-- 
Johann Spies          Telefoon: 021-808 4036
Informasietegnologie, Universiteit van Stellenbosch

     "My son, if sinners entice thee, consent thou not." 
                               Proverbs 1:10
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

end of thread, other threads:[~2002-06-20  9:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-19  8:54 [Caml-list] List.sort Johann Spies
2002-06-19 15:14 ` Stefano Zacchiroli
2002-06-19 15:16 ` Henri Dubois-Ferriere
2002-06-19 15:30   ` sebastien FURIC
2002-06-19 15:26 ` Remi VANICAT
2002-06-19 17:27 ` Alessandro Baretta
2002-06-20  9:29   ` Johann Spies

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).