From: Dimitri Ara <dimitri@nerim.net>
To: caml-list@inria.fr
Subject: Re: wanted features (was: Re: [Caml-list] Bigarray map & set/get (long))
Date: 27 Jul 2002 14:06:06 +0200 [thread overview]
Message-ID: <87sn25v0i9.fsf@corwin.mutu.net> (raw)
In-Reply-To: <4.3.2.7.2.20020726173231.02b36ae0@mail.d6.com>
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
prev parent reply other threads:[~2002-07-27 12:06 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-07-19 13:59 [Caml-list] Bigarray map & set/get (long) Christophe TROESTLER
2002-07-20 18:29 ` Daniel de Rauglaudre
2002-07-21 0:45 ` Oleg
2002-07-22 13:30 ` [Caml-list] Bigarray map & set/get Christophe TROESTLER
2002-07-22 9:31 ` [Caml-list] Bigarray map & set/get (long) Xavier Leroy
2002-07-22 13:03 ` [Caml-list] Bigarray map & set/get Christophe TROESTLER
2002-07-22 15:43 ` [Caml-list] Bigarray map & set/get (long) Fernando Alegre
2002-07-25 3:02 ` Chris Hecker
2002-07-25 9:30 ` Xavier Leroy
2002-07-25 18:11 ` Chris Hecker
2002-07-26 5:44 ` Michael Vanier
2002-07-26 22:33 ` wanted features (was: Re: [Caml-list] Bigarray map & set/get (long)) Chris Hecker
2002-07-26 22:40 ` Michael Vanier
2002-07-26 22:44 ` Chris Hecker
2002-07-27 0:28 ` Michael Vanier
2002-07-27 0:32 ` Chris Hecker
2002-07-27 10:53 ` Dimitri Ara
2002-07-27 12:06 ` Dimitri Ara [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87sn25v0i9.fsf@corwin.mutu.net \
--to=dimitri@nerim.net \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox