caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] undocumented external ... = "%identity"
@ 2003-10-29 10:42 Stefano Zacchiroli
  2003-10-29 11:39 ` Jacques Garrigue
  0 siblings, 1 reply; 7+ messages in thread
From: Stefano Zacchiroli @ 2003-10-29 10:42 UTC (permalink / raw)
  To: Inria Ocaml Mailing List

It seems to me that the "%identity" feature, as in

  external unsafe_cast : 'a obj -> 'b obj = "%identity"

is undocumented. Am I wrong? If not is there any particular reason for
so? According to http://caml.inria.fr/archives/200208/msg00034.html is
not meant to be used by the end user, but if it's better than Obj.magic
and used by lablgtk I see no reason to not mention it in the
"Interfacing C with Objective Caml" chapter of the OCaml documentation.
Maybe with a huge disclaimer ...

Cheers.

-- 
Stefano Zacchiroli  --  Master in Computer Science @ Uni. Bologna, Italy
zack@{cs.unibo.it,debian.org,bononia.it}  -  http://www.bononia.it/zack/
"  I know you believe you understood what you think I said, but I am not
sure you realize that what you heard is not what I meant!  " -- G.Romney

-------------------
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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] undocumented external ... = "%identity"
  2003-10-29 10:42 [Caml-list] undocumented external ... = "%identity" Stefano Zacchiroli
@ 2003-10-29 11:39 ` Jacques Garrigue
  2003-10-30 19:55   ` Stefano Zacchiroli
  0 siblings, 1 reply; 7+ messages in thread
From: Jacques Garrigue @ 2003-10-29 11:39 UTC (permalink / raw)
  To: zack; +Cc: caml-list

From: Stefano Zacchiroli <zack@bononia.it>

> It seems to me that the "%identity" feature, as in
> 
>   external unsafe_cast : 'a obj -> 'b obj = "%identity"
> 
> is undocumented. Am I wrong? If not is there any particular reason for
> so? According to http://caml.inria.fr/archives/200208/msg00034.html is
> not meant to be used by the end user, but if it's better than Obj.magic
> and used by lablgtk I see no reason to not mention it in the
> "Interfacing C with Objective Caml" chapter of the OCaml documentation.
> Maybe with a huge disclaimer ...

It is equivalent to Obj.magic, which uses the same external.
The only interest is that you can choose to give it a type more
restrictive than Obj.magic, while still being an external.
This way %identity completely disappears during compilation.

I suppose that as Obj.magic is not documented, this is not documented
either. 

Jacques Garrigue

-------------------
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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] undocumented external ... = "%identity"
  2003-10-29 11:39 ` Jacques Garrigue
@ 2003-10-30 19:55   ` Stefano Zacchiroli
  2003-10-31  7:47     ` William Lovas
  0 siblings, 1 reply; 7+ messages in thread
From: Stefano Zacchiroli @ 2003-10-30 19:55 UTC (permalink / raw)
  To: caml-list

On Wed, Oct 29, 2003 at 08:39:35PM +0900, Jacques Garrigue wrote:
> I suppose that as Obj.magic is not documented, this is not documented
> either. 

Ok, thanks for your answer.

Now, let me restate my question: whi obj.magic _and_ "%identity" are not
documented? Usually undocumented stuff is stuff subject to changes, not
stable, ecc ...

Practically, a lot of people use Obj.magic when needed and it seems to
be part of the required knowledge to be a "discriminating hacker"(TM).
The reason that it's unsafe and can make your program crash, IMO, is not
a good reason not to have it documented. Indeed C interfacing APIs are
documented and they are as risky as using Obj.magic and friends.

Cheers.

-- 
Stefano Zacchiroli  --  Master in Computer Science @ Uni. Bologna, Italy
zack@{cs.unibo.it,debian.org,bononia.it}  -  http://www.bononia.it/zack/
"  I know you believe you understood what you think I said, but I am not
sure you realize that what you heard is not what I meant!  " -- G.Romney

-------------------
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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] undocumented external ... = "%identity"
  2003-10-30 19:55   ` Stefano Zacchiroli
@ 2003-10-31  7:47     ` William Lovas
  2003-11-01  8:22       ` Stefano Zacchiroli
  0 siblings, 1 reply; 7+ messages in thread
From: William Lovas @ 2003-10-31  7:47 UTC (permalink / raw)
  To: caml-list

On Thu, Oct 30, 2003 at 08:55:48PM +0100, Stefano Zacchiroli wrote:
> On Wed, Oct 29, 2003 at 08:39:35PM +0900, Jacques Garrigue wrote:
> > I suppose that as Obj.magic is not documented, this is not documented
> > either. 
> 
> Ok, thanks for your answer.
> 
> Now, let me restate my question: whi obj.magic _and_ "%identity" are not
> documented? Usually undocumented stuff is stuff subject to changes, not
> stable, ecc ...

Obj.magic's "behavior" *is* subject to change, since it depends upon the
underlying representation of values.  The Obj module's documentation is,
in a very real sense, the entire implementation of the O'Caml compiler and
runtime.

> Practically, a lot of people use Obj.magic when needed and it seems to
> be part of the required knowledge to be a "discriminating hacker"(TM).
> The reason that it's unsafe and can make your program crash, IMO, is not
> a good reason not to have it documented. Indeed C interfacing APIs are
> documented and they are as risky as using Obj.magic and friends.

It's a little more than just unsafe -- when you use the Obj module, your
program becomes dependent upon the implementation of O'Caml.

Also, while it's true that interacting with C code is just as unsafe as
using the Obj module, interacting with C code is also a lot *harder* than
using the Obj module.  Presumably, if one understands how to interface
O'Caml with C, they're aware of the risks and will exercise sufficient
care.  Even a seasoned hacker's careless use of Obj.magic can go awry, as
seen in the recent thread about IEEE floating point equality.

To be fair, David Monniaux posted a message once explaining when Obj.magic
is "okay" to use:

    http://pauillac.inria.fr/caml/caml-list/0975.html

Such "okay" uses are sufficiently bizarre, though, that it makes sense to
leave the Obj module undocumented -- anyone who needs it will already
understand how it works.

cheers,
William

-------------------
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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] undocumented external ... = "%identity"
  2003-10-31  7:47     ` William Lovas
@ 2003-11-01  8:22       ` Stefano Zacchiroli
  2003-11-03 14:03         ` Damien Doligez
  0 siblings, 1 reply; 7+ messages in thread
From: Stefano Zacchiroli @ 2003-11-01  8:22 UTC (permalink / raw)
  To: caml-list

On Fri, Oct 31, 2003 at 02:47:48AM -0500, William Lovas wrote:
> Obj.magic's "behavior" *is* subject to change, since it depends upon
> the underlying representation of values.  The Obj module's
> documentation is, in a very real sense, the entire implementation of
> the O'Caml compiler and runtime.

The fact that Obj.magic _implementation_ depends on the entire
implementation of the OCaml compiler and runtime, doesn't imply that its
_interface_ does as well.

If I'm using Obj.magic I'm supposed to know what I'm doing (the examples
reported in the post you mentioned are significative here) and that I'm
sure that the type magic I'm doing are correct. In such a case the
correctness of those magics will change only when the assumption on
which their correction rely changes, for example a change in the type
system.

Such major changes are usually backward compatibile, if not I suppose
the Obj.magic forward porting problem will be the minor problem
programmer will have with a new ocaml release ...

If I look at the post you mentioned, I see that it's from January 1999,
and Obj.magic usage seems to be exactly the same as today.

> Such "okay" uses are sufficiently bizarre, though, that it makes sense to
> leave the Obj module undocumented -- anyone who needs it will already
> understand how it works.

Poor point, I still don't think such a feature should be mentioned just
on this mailing list and in the lablgtk code. Why not adding it to the
documentation with a huge disclaimeir?

Cheers.

-- 
Stefano Zacchiroli  --  Master in Computer Science @ Uni. Bologna, Italy
zack@{cs.unibo.it,debian.org,bononia.it}  -  http://www.bononia.it/zack/
"  I know you believe you understood what you think I said, but I am not
sure you realize that what you heard is not what I meant!  " -- G.Romney

-------------------
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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] undocumented external ... = "%identity"
  2003-11-01  8:22       ` Stefano Zacchiroli
@ 2003-11-03 14:03         ` Damien Doligez
  2003-11-03 14:20           ` Nicolas Cannasse
  0 siblings, 1 reply; 7+ messages in thread
From: Damien Doligez @ 2003-11-03 14:03 UTC (permalink / raw)
  To: caml-list

On Saturday, November 1, 2003, at 09:22 AM, Stefano Zacchiroli wrote:

> The fact that Obj.magic _implementation_ depends on the entire
> implementation of the OCaml compiler and runtime, doesn't imply that 
> its
> _interface_ does as well.

Depends on what you mean by "interface".  The _specification_ of 
Obj.magic
depends on many implementation choices of the compiler and runtime.

> If I'm using Obj.magic I'm supposed to know what I'm doing (the 
> examples
> reported in the post you mentioned are significative here) and that I'm
> sure that the type magic I'm doing are correct. In such a case the
> correctness of those magics will change only when the assumption on
> which their correction rely changes, for example a change in the type
> system.

... or a change in the data representations used by the compiler and
runtime.

> Such major changes are usually backward compatibile, if not I suppose
> the Obj.magic forward porting problem will be the minor problem
> programmer will have with a new ocaml release ...

Not true.  We can make changes that break many uses of Obj.magic without
changing the language or the type system.  That's why Obj.magic is not
documented.

-- Damien

-------------------
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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] undocumented external ... = "%identity"
  2003-11-03 14:03         ` Damien Doligez
@ 2003-11-03 14:20           ` Nicolas Cannasse
  0 siblings, 0 replies; 7+ messages in thread
From: Nicolas Cannasse @ 2003-11-03 14:20 UTC (permalink / raw)
  To: Damien Doligez, caml-list

[...]
> ... or a change in the data representations used by the compiler and
> runtime.
>
> > Such major changes are usually backward compatibile, if not I suppose
> > the Obj.magic forward porting problem will be the minor problem
> > programmer will have with a new ocaml release ...
>
> Not true.  We can make changes that break many uses of Obj.magic without
> changing the language or the type system.  That's why Obj.magic is not
> documented.

To be 100% honest, you should say that such a change would break most of the
Ocaml interfaces to C librairies, and that such a change have is then highly
unexpectable (at least I hope so for the sake of Ocaml). Documenting
Obj.magic would have the benefit to make people better understand the
underlying C representation of caml values, and then writing more efficient
code - and start writing more C libraries....

Nicolas Cannasse

-------------------
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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2003-11-03 14:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-29 10:42 [Caml-list] undocumented external ... = "%identity" Stefano Zacchiroli
2003-10-29 11:39 ` Jacques Garrigue
2003-10-30 19:55   ` Stefano Zacchiroli
2003-10-31  7:47     ` William Lovas
2003-11-01  8:22       ` Stefano Zacchiroli
2003-11-03 14:03         ` Damien Doligez
2003-11-03 14:20           ` Nicolas Cannasse

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).