Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] List.sort
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-06-19 (15:15)
From: Stefano Zacchiroli <zack@c...>
Subject: Re: [Caml-list] List.sort
On Wed, Jun 19, 2002 at 10:54:54AM +0200, Johann Spies wrote:
> I am trying to figure out how to use List.sort.

Look at the List.sort type:

  ('a -> 'a -> int) -> 'a list -> 'a list

the first "argument" required by List.sort have type "function that
takes two arguments of the same type and return an int".
The type of compare is:

  'a -> 'a -> int

you then have to pass the function compare itself without applying it
(as I saw in one of your example).
This is a sample usage:

  List.sort compare [3;2;1]

Indeed "List.sort compare" have type

  'a list -> 'a list


Stefano Zacchiroli - undergraduate student of CS @ Univ. Bologna, Italy | ICQ# 33538863 |
"I know you believe you understood what you think I said, but I am not
sure you realize that what you heard is not what I meant!" -- G.Romney
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: