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
Circuralizing lists
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-11-26 (22:50)
From: Jon Harrop <jon@f...>
Subject: Re: [Caml-list] Circuralizing lists
On Monday 26 November 2007 21:46, Till Varoquaux wrote:
> Writing the list containing an inifinite number of ones can easily be done
> as:
> let rec ones = 1::ones
> I however don't know of any type safe to generate the infinite list
> which is the repetition of a given list (in a type safe non lazy way).
> What I'm looking for is a code that would do:
> let circularize  = function
>     | [] -> failwith "cannot circularize empty lists"
>     | l -> let rec res = l@res in res
> Is this at all possible?

OCaml only permits restricted static forms of this construct. The only 
practical application of this restricted form that I am aware of is in 
avoiding dummy values when creating simple cycles such as the environments of 
recursive closures in an interpreter.

Dr Jon D Harrop, Flying Frog Consultancy Ltd.