I am a noob and do not understand this error

This expression has type unit → widget
but an expression was expected of type widget = (unit, [ `C ]) pointer
Hint: Did you forget to provide () as argument?

I am using my own attempt at using gtk and ctypes
my code fragment
error happens on: widget_set_vexpand canvas true


let application_add_window =
  foreign ~from:libgtk "gtk_application_add_window"
    (application @-> gpointer @-> returning void)

let box_new =
  foreign ~from:libgtk "gtk_box_new" (int @-> int @-> returning widget)

let drawing_area_new =
  foreign ~from:libgtk "gtk_drawing_area_new" (void @-> returning widget)

let widget_set_vexpand =
  foreign ~from:libgtk "gtk_widget_set_vexpand"
    (widget @-> bool @-> returning void)

let activate : application -> gpointer -> unit =
 fun app _data ->
  let win = gtk_application_window_new app in
  application_add_window app win ;
  window_set_title win "Gtk Minimal" ;
  window_set_default_size win 600 400 ;
  (* create box with orientation vertical and spacing 0 *)
  let box = box_new 1 0 in
  let canvas = drawing_area_new in
  widget_set_vexpand canvas true ;
  (* create canvas drawing area *)
  (* set canvas attributes: expand and callback fn *)
  (* set canvas events *)
  (* append canvas to box *)
  (* set box as child of win *)
  (* set win events *)
  window_present win

Found this

and got the clue;

I needed to add the () as an argument

let canvas = drawing_area_new () in

Notice how the compiler suggested exactly this:

3 Likes