Re: Obj.magic
Subject: Re: Obj.magic
Newsgroups: gmane.comp.lang.ocaml.beginners
Date: 2008-11-18 15:39:52 GMT
Thanks very much.
I'm studying OcamlP3L system and in its source there is a large use of Obj.magic, so I wanted to know something deeper about it.
Bye,
nicoletta
--- Mar 18/11/08, Dario Teixeira <darioteixeira <at> yahoo.com> ha scritto:
Da: Dario Teixeira <darioteixeira <at> yahoo.com>
Oggetto: Re: "ocaml_beginners"::[] Obj.magic
A: ocaml_beginners <at> yahoogroups.com
Data: Martedì 18 novembre 2008, 16:25
Hi,
> I can't find exhaustive documentation about this
> function. Could somebody explain me its specification?
The first rule of Obj.magic is that you do not talk about
Obj.magic... On a more serious note, Obj.magic is used to
"magically" overrule the type system, allowing you to do
a low-level cast of a type into another. As an example,
try this code in the top-level:
let foo : float = Obj.magic 1;;
Note that this is not a safe type-casting. In fact, on my
machine the above example causes a segfault.
While gurus can certainly find situations where Obj.magic is
indeed useful, I reckon it's almost certain that if you think
you might need Obj.magic, then there must be something wrong
with your design or you are trying to do things which are not
possible within the Ocaml type system.
Cheers,
Dario Teixeira
Unisciti alla community di Io fotografo e video, il nuovo corso di fotografia di Gazzetta dello sport:
http://www.flickr.com/groups/iofotografoevideo
[Non-text portions of this message have been removed]
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch format to Traditional
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe
__,_._,___

RSS Feed