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
Re: Map is not tail recursive
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Juan Jose Garcia Ripoll <jjgarcia@i...>
Subject: The way Ocaml inlines
David McClain wrote:
> >(particularly if you inline it).
> Is there a way to explicitly inline functions, other than cut and paste?

By watching OCaml work, and studying the compiler, I've seen it inline
many small functions, even when they are defined in other modules. I
pretty much like this, but I find only one minor inconvenience about the
way OCaml inlines. It is this one: say that you have

	module Foo = struct
	let ap_succ f n = f (n +. 1.0)
	let test a =
	   let my_f x = cos x
	   in ap_succ my_f a

After inlining, the result is not a sort of
	let test a = cos (n +. 1.0)
but something like
	let my_f x = cos x
	let test a = generic_apply my_f (a +. 1.0)
It is even worse if `my_f' uses, for instance, `a', because then a
closure is built, which would not be necessary. I think this could be
solved by making the `inliner' a bit smarter and re-inlining the
functions that are applied. This would make it attractive and efficient
to write small useful functions in separate modules.


Juan Jose Garcia Ripoll		www:
Dpto. de Matematicas		job:
E.T.S.I. Industriales		home:
Univ. de Castilla-La Mancha, Ciudad Real E-13071 (Spain)