caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Remi VANICAT <vanicat@labri.u-bordeaux.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] real lazy?
Date: 21 Aug 2001 16:28:13 +0200	[thread overview]
Message-ID: <87pu9pa3nm.dlv@wanadoo.fr> (raw)
In-Reply-To: <200108211337.f7LDbGl36930@givry.rennes.enst-bretagne.fr>

Francis Dupont <Francis.Dupont@enst-bretagne.fr> writes:

> 3- streams (aka lazy lists)
> 
>  open Lazy
>  (* to get type t and function force *)

you could use Lazy.force and Lazy.t

> 
>  type 'a cell = Nil | Cons of 'a * 'a stream
>  and 'a stream = 'a cell Lazy.t
> 
>  but this type is not really polymorphic:
> 
>  «lazy Nil» has type «'_a cell Lazy.status ref» i.e. «'_a stream»
>  not «'a stream» as it should be!

it's not such a trouble. You could write a little function :

let nil () = lazy Nil

and create a new empty stream each time you need it. 
You could also use ocaml stream : (of type Stream.t, see the doc of
the modules, and thing about ocaml extension in the manual.)  It is
not exactly the same, but it's quite useful. 


> 
>  So in place of a module Stream I had to write a functor Stream
>  (with «sig type t end» as the argument signature) in order to
>  fix the type of elements of streams. Argh!!

i don't believe that a functor is such a trouble. and you can easily
make otherwise.

>  The real purpose of streams is to write:
> 
>  let map f =
>   let rec mapf s = 
>    lazy begin
>     match force s with
>      | Nil -> Nil
>      | Cons(x,r) -> Cons(f x,mapf r)
>    end
>   in mapf
> 
>  let rec nat = lazy (Cons(0,map succ nat))
>  and so on...

let nat =
   let rec aux n =
     lazy (Cons(n, aux (n+1))) in
   aux 0

is much better.

-- 
Rémi Vanicat
vanicat@labri.u-bordeaux.fr
http://dept-info.labri.u-bordeaux.fr/~vanicat
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


  reply	other threads:[~2001-08-21 15:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-21 13:37 Francis Dupont
2001-08-21 14:28 ` Remi VANICAT [this message]
2001-08-22  1:54 ` John Max Skaller
2001-08-23  8:26 ` Xavier Leroy

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=87pu9pa3nm.dlv@wanadoo.fr \
    --to=vanicat@labri.u-bordeaux.fr \
    --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;
as well as URLs for NNTP newsgroup(s).