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] 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: -- (:)
From: jmarant@n...
Subject: Re: [Caml-list] Using %identity for casting types
Jacques Garrigue <> 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 Archives:
Bug reports: FAQ:
Beginner's list: