Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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?

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

  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
Bug reports:  FAQ:
To unsubscribe, mail  Archives: