"David Allsopp" <dra-n...@metastack.com> writes:

> Goswin von Brederlow wrote:
>> "David Allsopp" <dra-n...@metastack.com> writes:
>> 
>> > external foo_of_bar : bar -> foo = "%identity"
>> >
>> > in *both* the .ml and .mli file for the module in question. I'm
>> virtually certain that ocamlopt eliminates calls to the %identity
>> primitive.
>> 
>> Where is that documented?
>
> The use of external and its benefit in exported signatures is documented in
> Chapter 18 of the manual.
>
> I believe I became aware of the %identity special handling as a side-effect
> of the discussion in
> http://caml.inria.fr/pub/ml-archives/caml-list/2007/04/200afc54d9796dbb7a8d7
> 5bef70f2496.en.html.
>
> If you look in asmcomp/cmmgen.ml you'll see what I think is the elimination
> of Pidentity calls in the code generator.

Meaning it is not documented. :(

>> I would have written
>> 
>> let foo_of_bar (x : bar) = (x :> foo)
>
> We're solving two different problems, I think (as you're assuming that bar
> can be constrained to type foo) - I'm assuming that all type constraining is
> done in the signature of the interface so, without %identity I would simply
> have put [let foo_of_bar x = x] of type 'a -> 'a in my module... and then
> constrained it as [val foo_of_bar : bar -> foo] in the signature.
>
> It is possible that ocamlopt can recognise (obvious) identity functions as
> well, but that's just speculation on my part as I haven't looked.

It probably won't detect it as identity function but it probably always
inlines it and thereby eliminates it. I hope.

MfG
        Goswin

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to