[ocaml-ctypes] Bigarray typing problem

Daniel Bünzli daniel.buenzli at erratique.ch
Wed Dec 4 18:13:06 GMT 2013


Hello,

Suppose I have a C function like this that takes a 256 element array prototyped like this:  

  void write (Uint16 *a); 

I would like to expose it as 

  val write : (int, Bigarray.int16_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t -> unit

tried something along 

  let write = foreign "write" (ptr uint16_t @-> returning void) 
  let write a = write (bigarray_start array1 a) 

But it fails on the second line with (for the parenthised expression) : 

  Error: This expression has type int Ctypes.ptr
  but an expression was expected of type Unsigned.uint16 Ctypes.ptr


It seems to me that bigarray_start has the wrong type, it should map to a pointer of the *storage* type of the bigarray, not the type used to read/write the bigarray. 

Besides I can't see how you can do that without introducing phantom witness values to make the translation from bigarray storage types to ctypes storage types (i.e. in that case from Bigarray.int16_unsigned_elt to uint16_t). 

I could just coerce the damn thing, but something feels wrong here. Am I missing something ? 

Thanks,

Daniel




More information about the Ctypes mailing list