Browse thread
[Caml-list] Bigarray map & set/get (long)
[
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: | Dimitri Ara <dimitri@n...> |
| Subject: | Re: wanted features (was: Re: [Caml-list] Bigarray map & set/get (long)) |
Chris Hecker <checker@d6.com> a écrit :
> >I can't find a link to any papers by Okasaki on this subject.
>
> http://citeseer.nj.nec.com/okasaki98view.html
One way to achieve okasaki goal is to provide in the module interface
a lazy concrete_type_of_abstract_type.
Thus, we could write Okasaki's example (page 15) this way:
module type SEQUENCE =
sig
type 'a t
val empty : 'a t
val cons : 'a -> 'a t -> 'a t
val append : 'a t -> 'a t -> 'a t
val lazy_list_of_sequence : 'a t -> 'a Stream.t
end
module Sequence : SEQUENCE =
struct
type 'a t = Empty | Cons of 'a * 'a t | Append of 'a t * 'a t
let empty = Empty
let cons hd tl = Cons hd tl
let append l1 l2 = Append l1 l2
let rec lazy_list_of_sequence = function
| Empty -> [< >]
| Cons a b -> [< 'a ; lazy_list_of_sequence b >]
| Append a b -> [< lazy_list_of_sequence a; lazy_list_of_sequence b >]
end
open Sequence
let length l =
let rec length_aux = parser
| [< 'hd ; tl >] ->
1 + length_aux tl
| [< >] -> 0 in
length_aux (lazy_list_of_sequence l)
let l = append (cons 1 (cons 2 (cons 3 empty))) (cons 4 empty) in
Printf.printf "%d\n" (length l)
It's syntactically heavy (on an easy example...), it's not
intellectually satisfying, it wastes memory, etc. but it
works :-)
Maybe some camlp4 syntactic sugar could do the trick.
--
Selon les logs, il y a des pertes de porteuses, mais surtout des
requêtes de déconnexion qui viennent de votre machine.
Il faut se rappeler que windows 95 est un systeme bio-dégradable.
-+- Support technique HOL in: Guide du Cabaliste Usenet - CQFD ! -+-
-------------------
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