Search the web
Sign In
New User? Sign Up
ocaml_beginners · Ocaml Beginners
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want to share photos of your group with the world? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Example of use of Lazy   Message List  
Reply | Forward Message #5981 of 11550 |
Hi,

I have been looking at some graph code in ML and Haskell (I think) and
have seen that lazy evaluation plays an important role when we are
dealing with cyclic DAGs (infinite structures). I then looked at the
O'Reilly book to see how one could do this in OCaml.

The book shows in page 109 "Infinite" data structures how this can be
done. However I also see we have the Lazy module. I did some
experimenting with this technique and cannot seem to use it to good
effect. The example I though of was identifying a sequence of two odd
numbers whose sum is 12 (=5+7). To do this I figured something like this:

(x,y) = sum_12_pair ( odd ( generate 0 ) )

generate - generate sequence natural numbers
odd - filter to remove all even numbers
sum_12_pair - test ever consecutive pair for the correct sum

I don't know if the above example can actually be used to experiment
with the realistic use of the Lazy module. Could someone show me how
this can be used in a very simple example (maybe the above is good
enough?) or alternativelly point me to a source with this info?

TIA,
Hugo F.



Tue May 30, 2006 8:08 am

hugotwo3
Offline Offline
Send Email Send Email

Forward
Message #5981 of 11550 |
Expand Messages Author Sort by Date

Hi, I have been looking at some graph code in ML and Haskell (I think) and have seen that lazy evaluation plays an important role when we are dealing with...
Hugo Ferreira
hugotwo3
Offline Send Email
May 30, 2006
8:14 am

... There are five ways to use laziness in OCaml: 1. Manually (i.e. writing your own environment for a "closure"). 2. Use a built-in closure. 3. Use the Lazy...
Jon Harrop
harropjon
Offline Send Email
May 30, 2006
9:11 am

Hi Jon, ... I am aware of the above options save for (2) and (5). Could you tell what is the difference between (1) and (2)? ... I have experimented very...
Hugo Ferreira
hugotwo3
Offline Send Email
May 30, 2006
9:37 am

... camlp4o includes the special syntax for streams, which used to be an experimental feature of the OCaml language but was abandoned (I don't know why). ...
Martin Jambon
BioMim
Offline Send Email
May 30, 2006
9:02 pm

... Because it wasn't. camlp4 is an official part of the ocaml language, and the special syntax was only transfered to camlp4, because camlp4 is the offical...
Remi Vanicat
dl_ens
Offline Send Email
May 30, 2006
10:17 pm

Hi Martin, ... What I really wanted to know is if the camlp4 syntax has any advantages in relations to the Streams module. ... Yes, I am aware of that. ... ...
Hugo Ferreira
hugotwo3
Offline Send Email
May 31, 2006
6:29 am

... By (1) I am referring to something like this: # module Nats : sig type t val first : int * t val next : t -> int * t end = struct type t = int let first =...
Jon Harrop
harropjon
Offline Send Email
May 30, 2006
11:41 pm

Hi, ... <snip...> ... <snip> ... Interesting use of the module. In regards to the second one I had only seen this used with structures. ... <snip> ... ...
Hugo Ferreira
hugotwo3
Offline Send Email
May 31, 2006
7:11 am

Hello, Jon pointed out that I can use the campl4 extension for lazy evaluation. I was looking at some code I am experimenting with and cannot see how I can use...
Hugo Ferreira
hugotwo3
Offline Send Email
May 30, 2006
10:27 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help