Loading ...
Sorry, an error occurred while loading the content.

Re: Lazy-module... and layziness ... examples/explanations?

Expand Messages
  • pranava108
    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
    Message 1 of 13 , Apr 2, 2006
    • 0 Attachment
      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 ocaml_beginners@yahoogroups.com, 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
      in ML-like
      > > 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:
      >
      >
      http://72.14.207.104/search?q=cache:YCeSwXJ6gnQJ:research.microsoft.com/Users/simonpj/papers/haskell-retrospective/HaskellRetrospective.ppt+haskell+lazy+purity+simon+peyton+jones&hl=en&gl=uk&ct=clnk&cd=2&client=firefox
      > or:
      http://research.microsoft.com/Users/simonpj/papers/haskell-retrospective/HaskellRetrospective.ppt
      >
      > Rich.
      >
      > --
      > Richard Jones, CTO Merjis Ltd.
      > Merjis - web marketing and technology - http://merjis.com
      > Team Notepad - intranets and extranets for business -
      http://team-notepad.com
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.