Re: Lazy-module... and layziness ... examples/explanations?
- On the subject of laziness, is the implementation using co-routines
or some alternative. What is the rationale for the choice made by the
implementors of 'lazy' in ocaml?
--- In firstname.lastname@example.org, Richard Jones <rich@...> wrote:
> On Fri, Feb 17, 2006 at 11:35:38AM +0100, Oliver Bandel wrote:
> > > and line 2 is a shortcut for the following pseudocode:
> > >
> > > let lines =
> > > if HAS_BEEN_RUN_BEFORE v then
> > > GET_RESULT v
> > > else (
> > > let result = v () in
> > > SAVE_RESULT v result;
> > > result
> > > )
> > >
> > > (which can't actually be written in ordinary OCaml, which is why you
> > > need the Lazy module and special support in the runtime system).
> > Why can't that be written in OCaml?
> > Wouldn't it be possible with closures, that
> > has a state-variable/value (bool would make sense),
> > that says, if it was called before or not?
> > And a datastructure/value, that also stores the
> > results of the computation...
> > ...should work?
> OK, so yes you're right it could be written in OCaml, but it would be
> fairly cumbersome and inefficient. OCaml runtime has special support
> (two special object tags and garbage collector support) to make the
> whole thing more efficient. If you go about implementing this
> yourself, remember also that you need to store and re-raise exceptions
> if the suspension threw one.
> > Lazyness is purely functional... Haskell has it built in...
> > ...why can't it be done in OCaml?
> > Isn't it this, what Okasaki has written about (and to implement it
> > languages)?!
> Laziness is orthogonal to pure functional. It's an evaluation
> strategy which just means that you don't eagerly evaluate function
> arguments. It's also very expensive and is one of the main reasons
> why Haskell is so slow. SPJ has virtually admitted that himself in
> this presentation:
> Richard Jones, CTO Merjis Ltd.
> Merjis - web marketing and technology - http://merjis.com
> Team Notepad - intranets and extranets for business -