Browse thread
[Caml-list] List.sort
-
Johann Spies
- Stefano Zacchiroli
- Henri Dubois-Ferriere
- Remi VANICAT
- Alessandro Baretta
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Alessandro Baretta <alex@b...> |
| Subject: | Re: [Caml-list] List.sort |
Johann Spies wrote:
>
> 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 ...
Objective Caml version 3.04+13 (2002-06-05)
# let k = [ 3; 2 ; 1];;
val k : int list = [3; 2; 1]
# List.sort compare k;;
- : int list = [1; 2; 3]
Does this solve your problem? You have to realize that
functions (like Pervasives.compare) are first class citizens
in O'Caml. That is, you can pass a function like List.sort
*another function* as a actual parameter.
This is a fairly elementary question. You should try to
avoid posting questions like this on this list; however, I
am more than willing to lend a hand, insofar as possible, so
you can write to me personally, but please mention "Caml" in
the subject.
Alex
-------------------
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