From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA01710; Fri, 2 Aug 2002 17:29:07 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA01650 for ; Fri, 2 Aug 2002 17:29:06 +0200 (MET DST) Received: from nef.ens.fr (nef.ens.fr [129.199.96.32]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g72FT5f21073 for ; Fri, 2 Aug 2002 17:29:05 +0200 (MET DST) Received: from clipper.ens.fr (clipper-gw.ens.fr [129.199.1.22]) by nef.ens.fr (8.10.1/1.01.28121999) with ESMTP id g72FT5o24986 ; Fri, 2 Aug 2002 17:29:05 +0200 (CEST) Received: from localhost (frisch@localhost) by clipper.ens.fr (8.12.3/jb-1.1) id g72FT41p023263 ; Fri, 2 Aug 2002 17:29:04 +0200 (MET DST) Date: Fri, 2 Aug 2002 17:29:04 +0200 (MET DST) From: Alain Frisch To: Diego Olivier Fernandez Pons cc: caml-list@inria.fr Subject: Re: [Caml-list] Streams In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=ISO-8859-1 Content-Transfer-Encoding: 8BIT X-Virus-Scanned: by amavisd-milter (http://amavis.org/) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hello Diego, On Fri, 2 Aug 2002, Diego Olivier Fernandez Pons wrote: > - serait-il possible de documenter un peu le module obj ? Peut-être > est-ce une mauvaise idée, dans la mesure où cela pourrait permettre à > des utilisateurs non avertis d'écrire du code dangereux Using Obj safely requires to know a little bit about the runtime representation of objects; and once you have this knowledge (after reading the section on interfacing with C in the manual, or the OCaml runtime source files), the module interface should be self-explanatory. > L'inconvénient est que l'on perd le polymorphisme de la liste vide. > N'y a t-il aucun moyen de s'en sortir en utilisant du Caml > conventionnel ? You have to explain to the typechecker that the Nil stream will never be patched: type 'a stream = | Nil | Patchable of 'a stream_patchable and 'a stream_patchable = { mutable data : 'a streamCell } and 'a streamCell = | Cons of 'a * 'a stream | Append of 'a stream * 'a stream | Delayed of (unit -> 'a stream) | Generator of int * (int -> int) * (int -> 'a) Of course, this is less efficient (one would like to write as in other ML dialects, type 'a stream = | Nil | Patchable of { mutable data : 'a streamCell } [see http://pauillac.inria.fr/~lefessan/src/ for such a patch to OCaml 2.02] ... Any plan to introduce this syntax in OCaml ? ) > ensuite je voudrais abstraire le type int du constreur Generator afin > que l'utilisateur puisse indicer sa fonction génératrice par le type > de son choix : > > | Generator of 'k * (k' -> 'k) * ('k -> 'a) > > seulement si je déclare un type ('k, 'a) streamCell alors on ne peut > plus utiliser des listes d'indexes de type différent alors qu'elles > sont "logiquement" compatibles puisque le type 'k ne sert qu'a > construire les nouvelles valeurs de type 'a > > comment limiter "l'étendue" du type 'k au seul constructeur > [Generator] ? Couln't you just abstract the generator outside the stream ? let gen ini f = let state = ref ini in (fun () -> state := f !state), (fun () -> !state);; Do you really need to keep the current state visible ? > - la forme spéciale lazy ressemble très fortement à la fonction lazy_ > ci-dessous mis à part qu'elle n'évalue pas ses arguments > > (* OCaml 3.04 *) > let lazy_ = function x -> ref (Lazy.Delayed (function () -> x)) > > Quels seraient les inconvénients (théoriques ? pratiques ?) d'une > forme spéciale [uneval_] qui serait équivalente à function () ->, > autrement dit > > uneval : 'a -> (unit -> 'a) > uneval_ x <=> function () -> x What do you mean by "forme spéciale" ? If you just want syntactic sugar, you can implement it yourself with Camlp4. ------------------- 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