caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Let-in vs beta-redex
@ 2003-09-01 16:15 Lukasz Stafiniak
  2003-09-01 18:09 ` John Gerard Malecki
  2003-09-02 10:26 ` Michal Moskal
  0 siblings, 2 replies; 3+ messages in thread
From: Lukasz Stafiniak @ 2003-09-01 16:15 UTC (permalink / raw)
  To: caml-list

Hi,

Is let-in more efficient than beta-redex or are they computationally
equivalent? Is let-in a syntax-sugar of beta-redex?

E.g.

let x = sin 2. in x *. x *. x;;

(fun x -> x *. x *. x) (sin 2.);;

Thank You in advance,
Kindest Regards,
Lukasz



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


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

* RE: [Caml-list] Let-in vs beta-redex
  2003-09-01 16:15 [Caml-list] Let-in vs beta-redex Lukasz Stafiniak
@ 2003-09-01 18:09 ` John Gerard Malecki
  2003-09-02 10:26 ` Michal Moskal
  1 sibling, 0 replies; 3+ messages in thread
From: John Gerard Malecki @ 2003-09-01 18:09 UTC (permalink / raw)
  To: Lukasz Stafiniak; +Cc: caml-list

Lukasz Stafiniak wrote (2003-09-01T18:15:54+0200):
 > Hi,
 > 
 > Is let-in more efficient than beta-redex or are they computationally
 > equivalent? Is let-in a syntax-sugar of beta-redex?

They may be conceptually different but they compile to pretty much teh
same thing.  A nice trick to learn about the code that ocamlc
generates is to use 'ocaml -dinstr'.  For example,


:; ocaml -dinstr
        Objective Caml version 3.07+beta 2

# let x = sin 2. in x *. x *. x;;
        const 2.
        ccall sin_float, 1
        push
        acc 0
        push
        acc 1
        push
        acc 2
        ccall mul_float, 2
        ccall mul_float, 2
        return 2

- : float = 0.751826944668992803
# (fun x -> x *. x *. x) (sin 2.);;
        const 2.
        ccall sin_float, 1
        push
        closure L1, 0
        appterm 1, 2
L1:     acc 0
        push
        acc 1
        push
        acc 2
        ccall mul_float, 2
        ccall mul_float, 2
        return 1

- : float = 0.751826944668992803
# 

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


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

* Re: [Caml-list] Let-in vs beta-redex
  2003-09-01 16:15 [Caml-list] Let-in vs beta-redex Lukasz Stafiniak
  2003-09-01 18:09 ` John Gerard Malecki
@ 2003-09-02 10:26 ` Michal Moskal
  1 sibling, 0 replies; 3+ messages in thread
From: Michal Moskal @ 2003-09-02 10:26 UTC (permalink / raw)
  To: Lukasz Stafiniak; +Cc: caml-list

On Mon, Sep 01, 2003 at 06:15:54PM +0200, Lukasz Stafiniak wrote:
> Hi,
> 
> Is let-in more efficient than beta-redex or are they computationally
> equivalent? Is let-in a syntax-sugar of beta-redex?
> 
> E.g.
> 
> let x = sin 2. in x *. x *. x;;
> 
> (fun x -> x *. x *. x) (sin 2.);;

let in is *not* equivalent to beta-redex because of typing. Type
variables are not generalized in beta-redex, for example consider:

let id x = x in
(id 1, id true)

vs.

(fun id -> (id 1, id true)) (fun x -> x)

-- 
: Michal Moskal :: http://www.kernel.pl/~malekith : GCS {C,UL}++++$ a? !tv
: PLD Linux ::::::::: Wroclaw University, CS Dept : {E-,w}-- {b++,e}>+++ h

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


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

end of thread, other threads:[~2003-09-02 10:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-01 16:15 [Caml-list] Let-in vs beta-redex Lukasz Stafiniak
2003-09-01 18:09 ` John Gerard Malecki
2003-09-02 10:26 ` Michal Moskal

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