From: Ivan <ivg@ieee.org>
To: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: [Caml-list] passing object to a function fails to compile (lablgtk2 involved)
Date: Mon, 16 Jul 2012 10:49:51 +0400 [thread overview]
Message-ID: <678391342421391@web21g.yandex.ru> (raw)
Excuse me for the topic formulation, but I cannot state it better.
I have two simple functions:
let fill_model model name_col value_col =
let pars = P.from_file "parallax.cfg" in
let add_record (name, value) =
let iter = model#append () in
model#set ~row:iter ~column:name_col name;
model#set ~row:iter ~column:value_col value
in List.iter add_record pars
(where P.from_file some function generating an assoc list -> (string * string) list )
and
let create_model () =
let cols = new GTree.column_list in
let name_col = cols#add Gobject.Data.string
and value_col = cols#add Gobject.Data.string in
let model = GTree.list_store cols in
(model, name_col, value_col)
When I try to pass values returned by function `create_model' to function `fill_model' with the following expression:
let model, name_col, value_col = create_model () in
fill_model model name_col value_col
compiler refuses with:
Error: This expression has type GTree.list_store
but an expression was expected of type
< append : unit -> Gtk.tree_iter;
set : row:Gtk.tree_iter -> column:'a -> Types.id -> unit; .. >
The universal variable 'b would escape its scope
If I write the two functions in one, like this:
let fill_and_create_model () =
let cols = new GTree.column_list in
let name_col = cols#add Gobject.Data.string
and value_col = cols#add Gobject.Data.string in
let model = GTree.list_store cols in
let pars = P.resolve_links (P.from_file "parallax.cfg") in
let add_record (name, value) =
let iter = model#append () in
model#set ~row:iter ~column:name_col name;
model#set ~row:iter ~column:value_col "shit"
in List.iter add_record pars
everything compiles without a notice.
Please, can somebody explain me what I am doing wrong, and what is "universal variable 'b" that escapes from its scope.
Big thanks, in advance for any help!
next reply other threads:[~2012-07-16 6:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-16 6:49 Ivan [this message]
2012-07-16 15:29 ` Anthony Tavener
2012-07-17 8:32 ` Ivan
2012-07-18 16:53 ` Olivier Andrieu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=678391342421391@web21g.yandex.ru \
--to=ivg@ieee.org \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox