You would write it like this:

List.stable_sort ~cmp:(fun left right -> compare (fst left) (fst
right)) l

(assuming you want to order the list by the first element of each
pair)

On Jan 23, 7:15 am, Ivo Seeba <[email protected]> wrote:
> If i have a list
> let l = [(2;"a");(5,"b");(1,"dasdf")];;
> How to use a function List.stable_sort
>
> val stable_sort : cmp:('a -> 'a -> int) -> 'a list -> 'a list
>
> How to write correctly
> "l = List.stable_sort (cmp (fst 'a)(snd 'a)????) l;;"
> --
> All the best: Ivo
>
> 2010/12/27 Martin Jambon <[email protected]>
>
>
>
>
>
>
>
> > On 12/26/10 09:30, Ivo Seeba wrote:
> > > I need a list, or other structures, that enables insert elements of
> > > different types.
> > > I need a list like [("A",3);("B",[2;3;4]);("A",[[3;4];[1;2]])];.
> > > or like
> > > let st = ref ();;
> > > let insert b = (st:=(b,!st));;
> > > insert ("A",3);;
> > > insert ("B",[1;2]);;
>
> > > or.
>
> > > let st = ();;
> > > let insert b = ( let st = (b,st) );;
> > > ..
> > > Can anybody help me?
>
> > Variants (aka sum types, algebraic data types or tagged unions) are made
> > for that purpose:
>
> > type value = Int of int | List of value list
>
> > let l = [
> >  ("A", Int 3);
> >  ("B", List [ Int 2; Int 3; Int 4] );
> >  ("A", List [ List [ Int 3; Int 4 ];
> >               List [ Int 1; Int 2 ] ])
> > ]
>
> > Martin
>
> > > --
> > > All the best and a happy new year: Ivo
>
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "ocaml-developer" group.
> > > To post to this group, send email to [email protected]
> > > To unsubscribe from this group, send email to
> > > [email protected]
> > > For more options, visit this group at
> > >http://groups.google.com/group/ocaml-developer?hl=en
> > > For other OCaml forums, see
> >http://caml.inria.fr/resources/forums.en.html
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "ocaml-developer" group.
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]
> > For more options, visit this group at
> >http://groups.google.com/group/ocaml-developer?hl=en
> > For other OCaml forums, seehttp://caml.inria.fr/resources/forums.en.html

-- 
You received this message because you are subscribed to the Google Groups 
"ocaml-developer" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/ocaml-developer?hl=en
For other OCaml forums, see http://caml.inria.fr/resources/forums.en.html

Reply via email to