Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] about Obj.magic
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: John Max Skaller <skaller@o...>
Subject: Re: [Caml-list] about Obj.magic
Pierre Weis wrote:

>>An 'almost legal' use of Obj.magic is to populate an array with dummy 
>>values.
>>For example:
>>
>>    class Deep  ..
>>    let a = Array.make 100  (Obj.magic 0 :> Deep) in
>>    let len_a = ref 0 in
>>
>>This is roughly as safe as an unsafe array access,
>>only now the array length is a variable.
>>
>>-- 
>>John Max Skaller, mailto:skaller@ozemail.com.au
>>snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia.
>>voice:61-2-9660-0850
>>
>
>I'm afraid that this use is not ``almost legal'' and, on the contrary,
>it is strongly discouraged by good programming practice!
>
And I'm sorry too, because it is the only way to achieve the desired effect:
Ocaml could do well with a variable length array in the standard 
library, IMHO.

-- 
John Max Skaller, mailto:skaller@ozemail.com.au
snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia.
voice:61-2-9660-0850




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