* Re: Map is not tail recursive
@ 1999-01-14 3:49 David McClain
1999-01-14 9:49 ` The way Ocaml inlines Juan Jose Garcia Ripoll
0 siblings, 1 reply; 2+ messages in thread
From: David McClain @ 1999-01-14 3:49 UTC (permalink / raw)
To: caml-list, Jacques GARRIGUE
>(particularly if you inline it).
Is there a way to explicitly inline functions, other than cut and paste?
- DM
-----Original Message-----
From: Jacques GARRIGUE <garrigue@kurims.kyoto-u.ac.jp>
To: caml-list@pauillac.inria.fr <caml-list@pauillac.inria.fr>
Date: Wednesday, January 13, 1999 04:27
Subject: Re: Map is not tail recursive
>From: "David McClain" <dmcclain@azstarnet.com>
>
>> Juan got me thinking about this problem... So here is a solution:
>>
>> external rplacd : 'a list -> 'a list -> unit = "rplacd"
>>
>> -- and the external C code is
>>
>> value rplacd(value cell, value item)
>> {
>> Store_field(cell,1,item);
>> return Val_unit;
>> }
>
>While this is undocumented, there is a slightly simpler way to define
>rplacd, wihout using C. This should be faster in most cases
>(particularly if you inline it).
>
>let rplacd (cell : 'a list) (item : 'a) =
> Obj.set_field (Obj.repr cell) 1 (Obj.repr item)
>
>As for using the null pointer to have more efficient representations
>in data-structures, this is theoretically possible (and I believe that
>Xavier Leroy had an implementation with it), but this is not in the
>current version of ocaml.
>
> Jacques
>
>---------------------------------------------------------------------------
>Jacques Garrigue Kyoto University garrigue at kurims.kyoto-u.ac.jp
> <A HREF=http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/>JG</A>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
* The way Ocaml inlines
1999-01-14 3:49 Map is not tail recursive David McClain
@ 1999-01-14 9:49 ` Juan Jose Garcia Ripoll
0 siblings, 0 replies; 2+ messages in thread
From: Juan Jose Garcia Ripoll @ 1999-01-14 9:49 UTC (permalink / raw)
To: Caml list
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
end
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.
Regards
Juanjo
--
Juan Jose Garcia Ripoll www: http://www.arrakis.es/~worm
Dpto. de Matematicas job: jjgarcia@ind-cr.uclm.es
E.T.S.I. Industriales home: worm@arrakis.es
Univ. de Castilla-La Mancha, Ciudad Real E-13071 (Spain)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1999-01-14 23:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-01-14 3:49 Map is not tail recursive David McClain
1999-01-14 9:49 ` The way Ocaml inlines Juan Jose Garcia Ripoll
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox