Browse thread
Safe Obj.magic container ?
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | David Teller <David.Teller@u...> |
| Subject: | Re: [Caml-list] Safe Obj.magic container ? |
Thanks for the clarification. Again, I only have polymorphic variants, no functions, no floats, no lazy values, etc. The reason why I need to go through some Obj conversion is essentially the same reason safe marshalling needs to go through that conversion: storing typed information on an untyped medium (or, in this case, polymorphically typed information on a non-polymorphically typed medium) -- along with a type certificate. It just happens that this less-richly-typed medium is an exception. Cheers, David P.S.: I have tried alternative solutions but the best I can come up with involves something like 30% slowdown on my testsuite. Which is a bit too much for something which is supposed to be speed-critical. On Fri, 2008-02-29 at 10:52 +0900, Jacques Garrigue wrote: > From: David Teller <David.Teller@univ-orleans.fr> > > > Interesting. Can I assume that, if my type is boxed (in this case, a > > polymorphic variant), I can successfully convert it to Obj.t and back ? > > Yes : polymorphic variants are either ints or normal blocks, so this > should work. This is also true for normal variants. Actually I don't > know of any non-uniform representation problem outside of floats. > > Note however that this problem of non-uniform representation is no the > only danger when using Obj.magic imprudently. I recall another problem > with functional values. I'm afraid only Xavier could explain that one. > > If you have only (polymorphic) variants, and if you keep the types > monomorphic (i.e. always add complete type annotations to Obj.magic or > Obj.obj), things should work properly in the current implementation. > > Of course you should limit that kind of uses to things like > persistant storage or C interfaces, where you have to go through an > untyped world anyway, and avoid it at all costs in plain ml programs. > > Jacques Garrigue > -- David Teller Security of Distributed Systems http://www.univ-orleans.fr/lifo/Members/David.Teller Angry researcher: French Universities need reforms, but the LRU act brings liquidations.