Browse thread
[Caml-list] generic programming
[
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: | Alain Frisch <frisch@c...> |
| Subject: | Re: [Caml-list] Streams |
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