English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
to merge list of lists
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-03-07 (14:33)
From: Roland Zumkeller <roland.zumkeller@g...>
Subject: Re: [Caml-list] to merge list of lists
On 05/03/07, Jon Harrop <jon@ffconsultancy.com> wrote:
> # let rec transpose list =
>     try map hd list :: transpose (map tl list) with _ -> [];;

Here is a slightly different version that raises an exception if the
given list is not quadratic:

let rec transpose xs =
  if for_all ((=) []) xs then [] else
    map hd xs :: transpose (map tl xs);;

-- 
http://www.lix.polytechnique.fr/~zumkeller/