From: jmarant@nerim.net (Jérôme Marant)
To: caml-list@inria.fr
Subject: Re: [Caml-list] Using %identity for casting types
Date: Sun, 04 Aug 2002 09:53:22 +0200 [thread overview]
Message-ID: <87u1mbukjx.fsf@marant.org> (raw)
In-Reply-To: <20020802232931I.garrigue@kurims.kyoto-u.ac.jp> (Jacques Garrigue's message of "Fri, 02 Aug 2002 23:29:31 +0900")
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.
Cheers,
--
Jérôme Marant
http://marant.org
-------------------
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
prev parent reply other threads:[~2002-08-04 22:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-08-02 13:48 Jérôme Marant
2002-08-02 14:29 ` Jacques Garrigue
2002-08-04 7:53 ` Jérôme Marant [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87u1mbukjx.fsf@marant.org \
--to=jmarant@nerim.net \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox