caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Implementation of lazy_t
@ 2008-11-10 16:31 Florian Lorenzen
  2008-11-10 17:01 ` [Caml-list] " David Teller
  2008-11-10 17:12 ` Mauricio Fernandez
  0 siblings, 2 replies; 5+ messages in thread
From: Florian Lorenzen @ 2008-11-10 16:31 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 860 bytes --]

Hello,

I would like to know how lazy datatype constructors are implemented in
OCaml. A look into the documentation of the Lazy module revealed that
the compiler uses a built-in type constructor lazy_t for this
purpose. Unfortunately, I could not find any information on lazy_t on
the web. My question is how lazy datatypes are handled internally
(without having to read the compiler's source code). Especially, if
lazy_t implements call-by-need in the sense that once evaluated
objects are not evaluated again (by means of sharing) or if it
implements call-by-name like one can do by inserting 0-ary lambda
abstractions in the constructor to suspend evaluation and applying
them to force evaluation?

Is there any documentation on the internals available or can someone
shine some light on this?

Thanks a lot and best regards,

Florian


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 260 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Implementation of lazy_t
  2008-11-10 16:31 Implementation of lazy_t Florian Lorenzen
@ 2008-11-10 17:01 ` David Teller
  2008-11-10 17:12 ` Mauricio Fernandez
  1 sibling, 0 replies; 5+ messages in thread
From: David Teller @ 2008-11-10 17:01 UTC (permalink / raw)
  To: Florian Lorenzen; +Cc: caml-list


On Mon, 2008-11-10 at 17:31 +0100, Florian Lorenzen wrote:
> Especially, if
> lazy_t implements call-by-need in the sense that once evaluated
> objects are not evaluated again (by means of sharing) or if it
> implements call-by-name like one can do by inserting 0-ary lambda
> abstractions in the constructor to suspend evaluation and applying
> them to force evaluation?

That's call-by-need indeed. 

Cheers,
 David
-- 
David Teller-Rajchenbach
 Security of Distributed Systems
  http://www.univ-orleans.fr/lifo/Members/David.Teller
 Angry researcher: French Universities need reforms, but the LRU act brings liquidations. 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Implementation of lazy_t
  2008-11-10 16:31 Implementation of lazy_t Florian Lorenzen
  2008-11-10 17:01 ` [Caml-list] " David Teller
@ 2008-11-10 17:12 ` Mauricio Fernandez
  2008-11-11  6:35   ` Andrej Bauer
  2008-11-13 10:22   ` Florian Lorenzen
  1 sibling, 2 replies; 5+ messages in thread
From: Mauricio Fernandez @ 2008-11-10 17:12 UTC (permalink / raw)
  To: caml-list

On Mon, Nov 10, 2008 at 05:31:15PM +0100, Florian Lorenzen wrote:
> Hello,
> 
> I would like to know how lazy datatype constructors are implemented in
> OCaml. A look into the documentation of the Lazy module revealed that
> the compiler uses a built-in type constructor lazy_t for this
> purpose. Unfortunately, I could not find any information on lazy_t on
> the web. My question is how lazy datatypes are handled internally
> (without having to read the compiler's source code). Especially, if
> lazy_t implements call-by-need in the sense that once evaluated
> objects are not evaluated again (by means of sharing) or if it
> implements call-by-name like one can do by inserting 0-ary lambda
> abstractions in the constructor to suspend evaluation and applying
> them to force evaluation?
> 
> Is there any documentation on the internals available or can someone
> shine some light on this?

See stdlib/camlinternalLazy.ml --- force takes but 6 lines of code.

-- 
Mauricio Fernandez  -   http://eigenclass.org


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Implementation of lazy_t
  2008-11-10 17:12 ` Mauricio Fernandez
@ 2008-11-11  6:35   ` Andrej Bauer
  2008-11-13 10:22   ` Florian Lorenzen
  1 sibling, 0 replies; 5+ messages in thread
From: Andrej Bauer @ 2008-11-11  6:35 UTC (permalink / raw)
  To: caml-list

If I may advertise myself, have a look at the implementation of
MiniHaskell at the PL Zoo, http://andrej.com/plzoo/ . It has lazy
lists, and the code is supposed to be educational.

Hmm, looking at interp.ml I see that it's not as call-by-need as it
could be. So, a good exercise then is to fix the interpreter to make
it lazier :-)

Best regards,

Andrej

> On Mon, Nov 10, 2008 at 05:31:15PM +0100, Florian Lorenzen wrote:
>> I would like to know how lazy datatype constructors are implemented in
>> OCaml.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Implementation of lazy_t
  2008-11-10 17:12 ` Mauricio Fernandez
  2008-11-11  6:35   ` Andrej Bauer
@ 2008-11-13 10:22   ` Florian Lorenzen
  1 sibling, 0 replies; 5+ messages in thread
From: Florian Lorenzen @ 2008-11-13 10:22 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 234 bytes --]

Mauricio Fernandez wrote:
> On Mon, Nov 10, 2008 at 05:31:15PM +0100, Florian Lorenzen wrote:
> See stdlib/camlinternalLazy.ml --- force takes but 6 lines of code.
Thank you Mauricio. That pointer helped.

Regards,

Florian


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 260 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-11-13 10:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-10 16:31 Implementation of lazy_t Florian Lorenzen
2008-11-10 17:01 ` [Caml-list] " David Teller
2008-11-10 17:12 ` Mauricio Fernandez
2008-11-11  6:35   ` Andrej Bauer
2008-11-13 10:22   ` Florian Lorenzen

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).