Version française
Home     About     Download     Resources     Contact us    
Browse thread
Coercion of arrays of objects (and some other containers)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Martin Jambon <martin_jambon@e...>
Subject: Coercion of arrays of objects (and some other containers)
Here is my problem:

# let obj =
object
  method a = ()
  method b = ()
end;;
        val obj : < a : unit; b : unit > = <obj>

(* That is nice: *)
# ([ obj ] :> < a : unit > list);;
- : < a : unit > list = [<obj>]

(* But why doesn't it work with arrays? *)
# ([| obj |] :> < a : unit > array);;
Characters 1-10:
  ([| obj |] :> < a : unit > array);;
   ^^^^^^^^^
This expression cannot be coerced to type < a : unit > array; it has type
  < a : unit; b : unit > array
but is here used with type < a : unit > array
Only the first object type has a method b


In practice I have this problem with a hash table of objects, and I
expected it to work since it works fine with lists of the same
type of objects...
Is there any workaround?

Martin

--
Martin Jambon, PhD
http://martin.jambon.free.fr