I’m experimenting with ctypes, following the instructions here. I have something basic working:
module Types (F : Ctypes.TYPE) = struct
open F
type error_stack
let error_stack: error_stack structure typ = structure "ErrorStack"
end
module Functions (F : Ctypes.FOREIGN) = struct
open F
open Types
let error_stack_create = foreign "error_stack_create" (void @-> returning (ptr error_stack))
end
and now I would like to define a type alias to the ErrorStruct* and use it in a record. This works:
(* in Types *)
type error_stack_p = error_stack ptr
let error_stack_p = ptr error_stack
(* in Functions *)
let error_stack_create = foreign "error_stack_create" (void @-> returning error_stack_p)
but when I add this to my main code
type err = {
error_stack: C.Types.error_stack_p;
}
let () =
let error_stack = C.Functions.create_error_stack () in
{ error_stack }
it errors with
File "lib/piet.ml", line 10, characters 4-15:
10 | { error_stack }
^^^^^^^^^^^
Error: This expression has type
Piet__Function_description.Types.error_stack structure
Ctypes_static.ptr =
(Piet__Function_description.Types.error_stack structure, [ `C ])
pointer
but an expression was expected of type
C.Types.error_stack_p =
(Types_generated.error_stack, [ `C ]) pointer
Type
Piet__Function_description.Types.error_stack structure =
(Piet__Function_description.Types.error_stack, [ `Struct ])
structured
is not compatible with type Types_generated.error_stack