caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Johann Spies <jspies@sun.ac.za>
To: caml-list@inria.fr
Subject: [Caml-list] List.sort
Date: Wed, 19 Jun 2002 10:54:54 +0200	[thread overview]
Message-ID: <20020619085454.GA5244@adept.co.za> (raw)

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


             reply	other threads:[~2002-06-19 14:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-19  8:54 Johann Spies [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020619085454.GA5244@adept.co.za \
    --to=jspies@sun.ac.za \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).