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] Obj.magic, Obj.t etc.
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: [Caml-list] Obj.magic, Obj.t etc.
From: Christopher Dutchyn <>

> In a few instances I've encountered code with these special types.
> The former appears to be a way to "hint" the typechecker with
> additional information, and the latter seems to be some sort of
> catchall.
> Where are these documented?  Are there any others?

Related functions are all in the Obj module.
They are not documented as ML function because almost all of them can
break type safety when used incorrectly.

On the other hand, they are just equivalent to C macros described in
the "interfacing C" part of the manual, so you can consider this as

As an interesting aside, I've discovered recently that even Obj.repr
is dangerous:

# Obj.repr;;
- : 'a -> Obj.t = <fun>
# let arr = Array.create 1 (Obj.repr 1.0);;
val arr : Obj.t array = [|<abstr>|]
# arr.(0) <- Obj.repr 1;;
Segmentation fault

>From a subtyping point of view, this basically means that there cannot
be any "top" element in the ocaml type system.

Jacques Garrigue

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: