caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jason Smith <jns28@student.canterbury.ac.nz>
To: caml-list <caml-list@inria.fr>
Subject: Re: lazyness in ocaml (was : [Caml-list] kprintf with user formatters)
Date: Wed, 28 Jul 2004 22:17:09 +1200	[thread overview]
Message-ID: <190e01c4748c$0b657b20$b509b584@Praxis> (raw)
In-Reply-To: <200407280726.JAA01775@pauillac.inria.fr>

Hello, first off I come from a Haskell background, and especially ghc so I
might be a little off key here, but I thought I'd add my thoughts come what
may. Also I'm a newbie so go easy if I'm off base :) (which is more then
likely!)


> I cannot understand that one. We have that in Caml already and we had
> it from the very begining of Caml (1984). For instance, if I write
>
> f (expr)
>
> could you tell me ``if  f(expr) can modifiy expr or not [without
> finding which 'f' it is and examining it]'' ?
>
> To the best of my knowledge, the answer is no.

Well thats kinda what strictness analysis does. If f is going to use the
expression then we evaluate it before entering the function so we don't have
to pass around THUNKS. But yes we have to know what the 'f' is were playing
with.

> To the best of my knowledge, nobody never complained about that feature.

Its an optimization that is performed regularly in the ghc compiler, and
yeah no one complains about its abscence! :)

> > > In the lazy case it would destroy an important identity:
> >
> > f x <==> let x' = x in f x'
> >
> > With your rule, the LHS might not evaluate x, whereas the RHS
> > would.

I'm not exactly sure why u defined the substitution principle like this, the
syntax should be a non-issue.  The way I learned it (from Mitchells
excellent book) was the following. The substitution lemma intuitively says
that susbtituting a term N for a variable x in M is the same effect on the
meaning of M as changing the environment so that the value of x is the value
of N.

The meaning is what matters, not its syntactic form. If we use just plain
alegbra here, where S is the set of sorts, G the environment assigning types
to terms, we can define it as given M 'elem' Terms(S, G, x:s'), and N 'elem'
Terms(S, G), so that [N/x]M 'elem' Terms(S, G). Then for any environment E,
we can say that the denotational meaning (given by the meaning function  <
>) for each is the same, i.e.

<[N/x]M>E == <M>E{x -> a}

where a = <N>E is the meaning of N at E.

In the above, the meanings of an evaluated expression and an unevaluated
expression are as far as I'm aware identical.

In the prescence of side-effects this complicates the operational semantics
(and invalidates equivalences in the denotational semantics), because
side-effects change the storage semantics of the environment and can
invalidate the meaning function. For example when we substitute N for x in
M, evaluating N may change the meaning of a variable other then x free in M.

There are a number of papers by Sullivan and Wand discussing various
transformations like lambda lifting in a denotational model based on a
operational based term model where interaction is the basic observable, and
they don't consider the store as the final part of the congruence proof.
Anywayz, the problem with the above is that this equivelence already does
not hold in Ocaml'.

In Haskell the above identity phrased as it is, would hold, because we don't
have side effects. Threading of the world through the IO Monad forces the
same evaluation order for both expressions.

> Also, I didn't know that such an ``important identity'' stands for
> Caml expressions. Except in the trivial case where ``x'' just denotes
> a variable in the statment. In this case, the statment still holds with
> the new rule :)

>From what I can see yes it is broken because of side-effects, we cannot
guarentee that the two phrases are equivalent in the standard denotational
semantics.

> > Of course we already have that:
> >
> > f x y <=/=> let x' = x in y' = y in f x' y'
> >
> > since the RHS guarrantees x is evaluated before y,
> > whilst it happens by chance in the current Ocaml implementation
> > the reverse is true for the LHS.
>
> So what? Is the ``important identity'' wrong after all, being wrong in
> this case ? Or do you suggest to suppress currying in order to restore
> the ``important identity'

I'm a bit behind the discussion but I think the original poster was just
pointing out that we can impose AOR reduction explicitly by using the let
constructs.

Cheers,
Jason.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  parent reply	other threads:[~2004-07-28 10:18 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-30 16:32 [Caml-list] kprintf with user formatters Damien
2004-07-14 21:10 ` Pierre Weis
2004-07-15  0:17   ` Markus Mottl
2004-07-15  7:30     ` David MENTRE
2004-07-15  7:59       ` Jean-Christophe Filliatre
2004-07-15 23:35         ` henri dubois-ferriere
2004-07-15  7:39     ` Damien
2004-07-15 12:19       ` Markus Mottl
2004-07-15 12:42         ` Basile Starynkevitch [local]
2004-07-15 13:45           ` Markus Mottl
2004-07-15 14:22             ` Basile Starynkevitch [local]
2004-07-15 14:57               ` Markus Mottl
2004-07-16  6:47               ` Pierre Weis
2004-07-16  7:13                 ` Jean-Christophe Filliatre
2004-07-16  7:23                   ` henri dubois-ferriere
2004-07-16  7:44                     ` Jean-Christophe Filliatre
2004-07-16 17:56                   ` Markus Mottl
2004-07-19  9:17                   ` Pierre Weis
2004-07-19  9:32                     ` Jean-Christophe Filliatre
2004-07-16  7:21                 ` henri dubois-ferriere
2004-07-16 17:44                 ` Markus Mottl
2004-07-19 10:10                   ` Pierre Weis
2004-07-19 10:43                     ` Jon Harrop
2004-07-21 15:52                       ` Pierre Weis
2004-07-21 17:43                         ` lazyness in ocaml (was : [Caml-list] kprintf with user formatters) Daniel Bünzli
2004-07-22 16:28                           ` Pierre Weis
2004-07-22 17:03                             ` William Lovas
2004-07-22 23:00                             ` skaller
2004-07-23  3:32                               ` William Lovas
2004-07-28  7:26                               ` Pierre Weis
2004-07-28  8:06                                 ` skaller
2004-07-28  8:29                                   ` Daniel Bünzli
2004-07-28  9:13                                   ` Pierre Weis
2004-07-28  9:36                                     ` skaller
2004-07-28  9:38                                     ` skaller
2004-07-28 10:17                                 ` Jason Smith [this message]
2004-07-28 12:31                                   ` skaller
2004-07-21 20:41                         ` [Caml-list] kprintf with user formatters Jon Harrop
2004-07-22 15:39                           ` Pierre Weis
2004-07-22 22:16                             ` [Caml-list] lazy evaluation: [Was: kprintf with user formatters] skaller
2004-07-22 22:42                             ` [Caml-list] kprintf with user formatters skaller
2004-07-22  8:05                         ` [Caml-list] wait instruction lehalle@miriad
2004-07-22  8:40                           ` Olivier Andrieu
2004-07-22 10:35                             ` lehalle@miriad
2004-07-22 10:33                           ` Vitaly Lugovsky
2004-07-16  6:17             ` [Caml-list] kprintf with user formatters Pierre Weis
2004-07-16 17:14               ` Markus Mottl
2004-07-19 10:00                 ` Pierre Weis
2004-07-16  6:02       ` Pierre Weis
2004-07-16  8:42         ` Damien
2004-07-19  9:00           ` Pierre Weis
2004-07-16 16:52         ` Markus Mottl
2004-07-19  9:28           ` Pierre Weis
2004-07-15 22:20     ` Pierre Weis
2004-07-15 23:01       ` Markus Mottl
2004-07-16 16:17     ` james woodyatt

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='190e01c4748c$0b657b20$b509b584@Praxis' \
    --to=jns28@student.canterbury.ac.nz \
    --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).