English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] Using %identity for casting types
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-08-04 (22:56)
From: jmarant@n...
Subject: Re: [Caml-list] Using %identity for casting types
Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp> writes:

> Well, not really, but if you're interfacing with C++, it's not more
> dangerous to do the cast in ocaml than in C++ (except if you use
> rtti).
> The above idiom is equivalent to
>     let unsafe_cast : 'a obj -> 'b obj = Obj.magic
> It may be more efficient, as the compiler knows that unsafe_cast is
> the identity, and can discard it. No code is generated.
> I also tend to prefer it because it makes clear the need to properly
> write types: such casts only make sense at a precise type, while
> Obj.magic is 'a -> 'b, which allows too much.
> And, as always, only use unsafe casts for non-ocaml data.
> Ocaml datatypes are expressive enough that you don't need unsafe
> casts for them.

Thanks a lot.


Jérôme Marant

To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners