From: Richard J. <ri...@an...> - 2008-06-08 09:32:25
|
On Sun, Jun 08, 2008 at 10:17:59AM +0100, rich wrote: > let hairy_string_of_float (d : float) = > let r = Obj.repr d in > Obj.set_tag r Obj.string_tag; > (Obj.obj r : string) In fact, thinking about this a bit more clearly, there's no need to set the tag at all if all you do is call 'String.unsafe_get', so this works: let hairy_string_of_float (d : float) = (Obj.magic d : string) Be really careful that you don't let the returned "string" escape into the wild though :-) It still looks like a double to the garbage collector and it's not a well-formed string either, so any function other than 'String.unsafe_get' is highly likely to fail. Rich. -- Richard Jones Red Hat |