Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Are multiple return values optimized?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Krishnaswami, Neel <neelk@c...>
Subject: [Caml-list] Are multiple return values optimized?
Hello,

Are multiple return values optimized to avoid heap-allocation 
like curried functions are? In Scheme and Lisp, I'm used to an 
expression like

  (define foo
    (lambda () (values 1 2 3)))

  (call-with-values foo
     (lambda (x y z) (+ x y z))

evaluating without doing any heap-allocation. Will the analgous
OCaml

  let foo() = (1, 2, 3)
 
  let x, y, z = foo()
  in x + y + z

also pass values on the stack or will a tuple be heap-allocated?
Simple experiments with ocamlopt -S suggest the latter, but it's
possible that there are optimized cases that I don't know how 
to write. 

--
Neel Krishnaswami
neelk@cswcasa.com
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr