Type annotation (obviously) needed...
Serge Le Huitouze <[email protected]> Tue, 7 Dec 2010 07:54:14 +0100
| Newsgroups | gmane.comp.lang.ocaml.lib.gtk |
|---|---|
| Message-ID | <[email protected]> |
Hi there,
I have a compilation error while compiling the attached program
[The command line is included at the beginning of the file.
In order to simplify compilation, I've inlined the glade-generated
code. Caution however: you still need the glade file to run the
program].
The important part of the error message (I reproduce the complete
error message at the end of this email, but it's probably not
necessary for you, experts) goes like this:
* The universal variable 'e would escape its scope
If I comment out lines containing "store#append" and "store#set"
in function "indirect_way" (lines #82 and #83), I have no problem.
Also, note that similar calls in "direct_way" pose no compilation
problem.
So my problem obviously has to do with type wizardry, and a
type annotation should do the trick.
But I've no clue as what (and where) this annotation should be!
Can someone help me?
Thanks in advance.
--Serge
Complete error message:
File "test2.ml", line 98, characters 21-41:
Error: This expression has type
(string * GTree.view * GTree.list_store * string GTree.column) list
but an expression was expected of type
(string * GTree.view *
(< append : unit -> Gtk.tree_iter; as_model : Gtk.tree_model;
coerce : GTree.model; flags : GtkEnums.tree_model_flags list;
foreach : (Gtk.tree_path -> Gtk.tree_iter -> bool) -> unit;
get : 'b. row:Gtk.tree_iter -> column:'b GTree.column -> 'b;
get_column_type : int -> Gobject.g_type;
get_iter : Gtk.tree_path -> Gtk.tree_iter;
get_iter_first : Gtk.tree_iter option;
get_path : Gtk.tree_iter -> Gtk.tree_path;
get_row_reference : Gtk.tree_path -> GTree.row_reference;
iter_children : ?nth:int ->
Gtk.tree_iter option -> Gtk.tree_iter;
iter_has_child : Gtk.tree_iter -> bool;
iter_n_children : Gtk.tree_iter option -> int;
iter_next : Gtk.tree_iter -> bool;
iter_parent : Gtk.tree_iter -> Gtk.tree_iter option;
misc : GObj.gobject_ops; n_columns : int;
row_changed : Gtk.tree_path -> Gtk.tree_iter -> unit;
set : row:Gtk.tree_iter ->
column:'c GTree.column -> string -> 'd;
.. >
as 'a) *
'c GTree.column)
list
Type
GTree.list_store =
< append : unit -> Gtk.tree_iter; as_model : Gtk.tree_model;
clear : unit -> unit; coerce : GTree.model;
connect : GTree.tree_sortable_signals;
flags : GtkEnums.tree_model_flags list;
foreach : (Gtk.tree_path -> Gtk.tree_iter -> bool) -> unit;
get : 'b. row:Gtk.tree_iter -> column:'b GTree.column -> 'b;
get_column_type : int -> Gobject.g_type;
get_iter : Gtk.tree_path -> Gtk.tree_iter;
get_iter_first : Gtk.tree_iter option;
get_path : Gtk.tree_iter -> Gtk.tree_path;
get_row_reference : Gtk.tree_path -> GTree.row_reference;
get_sort_column_id : (int * Gtk.Tags.sort_type) option;
has_default_sort_func : bool; insert : int -> Gtk.tree_iter;
insert_after : Gtk.tree_iter -> Gtk.tree_iter;
insert_before : Gtk.tree_iter -> Gtk.tree_iter;
iter_children : ?nth:int ->
Gtk.tree_iter option -> Gtk.tree_iter;
iter_has_child : Gtk.tree_iter -> bool;
iter_is_valid : Gtk.tree_iter -> bool;
iter_n_children : Gtk.tree_iter option -> int;
iter_next : Gtk.tree_iter -> bool;
iter_parent : Gtk.tree_iter -> Gtk.tree_iter option;
misc : GObj.gobject_ops;
move_after : iter:Gtk.tree_iter -> pos:Gtk.tree_iter -> bool;
move_before : iter:Gtk.tree_iter -> pos:Gtk.tree_iter -> bool;
n_columns : int; prepend : unit -> Gtk.tree_iter;
remove : Gtk.tree_iter -> bool;
row_changed : Gtk.tree_path -> Gtk.tree_iter -> unit;
set : 'e.
row:Gtk.tree_iter ->
column:'e GTree.column -> 'e -> unit;
set_default_sort_func : (GTree.model ->
Gtk.tree_iter -> Gtk.tree_iter -> int) ->
unit;
set_sort_column_id : int -> Gtk.Tags.sort_type -> unit;
set_sort_func : int ->
(GTree.model ->
Gtk.tree_iter -> Gtk.tree_iter -> int) ->
unit;
sort_column_changed : unit -> unit;
swap : Gtk.tree_iter -> Gtk.tree_iter -> bool >
is not compatible with type 'a
The universal variable 'e would escape its scope
_______________________________________________
Lablgtk mailing list
[email protected]
http://yquem.inria.fr/cgi-bin/mailman/listinfo/lablgtk
test2.ml
(text/x-ocaml, 3.4 KB)
(*
Compile with:
ocamlc -I +lablgtk2 -o test2 lablgtk.cma lablglade.cma gtkInit.cmo test2.ml
Execute with:
./test2
*)
(* CAUTION: MANUAL INLINING STARTS HERE *)
(* Automatically generated from ui1.glade by lablgladecc *)
class program ?(file="ui1.glade") ?domain ?autoconnect(*=true*) () =
let xmldata = Glade.create ~file ~root:"program" ?domain () in
object (self)
inherit Glade.xml ?autoconnect xmldata
val toplevel =
new GWindow.window (GtkWindow.Window.cast
(Glade.get_widget_msg ~name:"program" ~info:"GtkWindow" xmldata))
method toplevel = toplevel
val program =
new GWindow.window (GtkWindow.Window.cast
(Glade.get_widget_msg ~name:"program" ~info:"GtkWindow" xmldata))
method program = program
val frame1 =
new GBin.frame (GtkBin.Frame.cast
(Glade.get_widget_msg ~name:"frame1" ~info:"GtkFrame" xmldata))
method frame1 = frame1
val hbox_program =
new GPack.box (GtkPack.Box.cast
(Glade.get_widget_msg ~name:"hbox_program" ~info:"GtkHBox" xmldata))
method hbox_program = hbox_program
val treeview1_ =
new GTree.view (GtkTree.TreeView.cast
(Glade.get_widget_msg ~name:"treeview1_" ~info:"GtkTreeView" xmldata))
method treeview1_ = treeview1_
val button1_ =
new GButton.button (GtkButton.Button.cast
(Glade.get_widget_msg ~name:"button1_" ~info:"GtkButton" xmldata))
method button1_ = button1_
val treeview2_ =
new GTree.view (GtkTree.TreeView.cast
(Glade.get_widget_msg ~name:"treeview2_" ~info:"GtkTreeView" xmldata))
method treeview2_ = treeview2_
val button2_ =
new GButton.button (GtkButton.Button.cast
(Glade.get_widget_msg ~name:"button2_" ~info:"GtkButton" xmldata))
method button2_ = button2_
method reparent parent =
frame1#misc#reparent parent;
toplevel#destroy ()
method check_widgets () = ()
end
(* CAUTION: MANUAL INLINING ENDS HERE *)
let settings1_cols = new GTree.column_list
let settings1_col_filename : string GTree.column =
settings1_cols#add Gobject.Data.string
let settings1_store = GTree.list_store settings1_cols
let ac_multi_files = fun gui ->
["View #1", gui#treeview1_, settings1_store, settings1_col_filename]
let direct_way gui =
let msg = "View #1" in
gui#treeview1_#set_model (Some ( settings1_store :> GTree.model));
let renderer = (GTree.cell_renderer_text [], ["text",settings1_col_filename]) in
let col1 = GTree.view_column ~renderer () in
ignore (gui#treeview1_#append_column col1);
let row = settings1_store#append () in
settings1_store#set ~row ~column:settings1_col_filename msg;
Printf.printf "Treeview '%s' initialized\n" msg; flush stdout
let indirect_way l =
let init_one (msg, trvw, store, col) =
trvw#set_model (Some (store :> GTree.model));
let renderer = (GTree.cell_renderer_text [], ["text",col]) in
let col1 = GTree.view_column ~renderer () in
ignore (trvw#append_column col1);
(**)
let row = store#append () in
store#set ~row ~column:col msg;
(**)
Printf.printf "Treeview '%s' initialized\n" msg; flush stdout
in List.iter init_one l
let use_direct = ref true
let () =
let gui = new program () in
ignore (gui#toplevel#connect#destroy ~callback:GMain.Main.quit);
gui#toplevel#show ();
if !use_direct
then (direct_way gui)
else (indirect_way (ac_multi_files gui));
GMain.Main.main ();;
ui1.glade
(application/x-glade, 2.5 KB) - not displayed