This site is updated infrequently. For up-to-date information, please visit the new OCaml website at ocaml.org.

[Caml-list] Bigarray map & set/get (long)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
 Date: 2002-07-27 (12:06) From: Dimitri Ara 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 a lazy
concrete_type_of_abstract_type in the module interface.

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 as
intellectually satisfying as views are, etc. but it works :-)

Maybe some camlp4 syntactic sugar could do the trick.

--
Dimitri Ara
-------------------
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

```