From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id 988EE7ED34 for ; Mon, 16 Jul 2012 17:29:53 +0200 (CEST) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of anthony.tavener@gmail.com) identity=pra; client-ip=74.125.82.52; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="anthony.tavener@gmail.com"; x-sender="anthony.tavener@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail1-smtp-roc.national.inria.fr: domain of anthony.tavener@gmail.com designates 74.125.82.52 as permitted sender) identity=mailfrom; client-ip=74.125.82.52; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="anthony.tavener@gmail.com"; x-sender="anthony.tavener@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wg0-f52.google.com) identity=helo; client-ip=74.125.82.52; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="anthony.tavener@gmail.com"; x-sender="postmaster@mail-wg0-f52.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnABAN8yBFBKfVI0kGdsb2JhbABFqCKIFwGIdQgiAQEBAQkJDQcUBCOCIAEBAQMBEgITGQEbEgsBAwELBgULGiEiAREBBQEKEgYTEhCHWwEDBgYLnW4JA4wjgnGEZgoZJwMKV4hxAQUMizSGRwOIS4xwgRKNFz6EHQ X-IronPort-AV: E=Sophos;i="4.77,594,1336341600"; d="scan'208";a="167043144" Received: from mail-wg0-f52.google.com ([74.125.82.52]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 16 Jul 2012 17:29:52 +0200 Received: by wgbfg15 with SMTP id fg15so3754447wgb.9 for ; Mon, 16 Jul 2012 08:29:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=z3td3ynu6vQ1uGKMKfx4JpkYtRkqLyiOp2LW8J9J5Qw=; b=rYvsH3sRnRvlwALnBYrVy2t4Yc/hnAxFqptCu+7VPJaS677Tsz8woJ1fDVSdWvBOJO YWS3XptyPBCnyRyzMNq24P6YXCs4iv40x7Mh1x8YzRe2Qe1pbwz6qDqDUOT7swZu9Iof o5MErZJcmQEgIb0doRUPW6BFK8ZvlwOI3Qv09y2osTcJgbZtJ5qRfLeS6U5p4zdwqARX NxubEIQ36HJmMqSlHb0In+XjMgdbVOa6HmWq19teQxIJElHFID1klbZ04ko9Ims/ieW6 WNHBRp38VLFYDz4VaxmrdmcR0FMvmr+CAgbtcurQN5oyr1kv3ka4J1XmnVNrEDvXa8RA lBaA== MIME-Version: 1.0 Received: by 10.216.209.8 with SMTP id r8mr6489851weo.51.1342452592663; Mon, 16 Jul 2012 08:29:52 -0700 (PDT) Received: by 10.223.201.72 with HTTP; Mon, 16 Jul 2012 08:29:52 -0700 (PDT) In-Reply-To: <678391342421391@web21g.yandex.ru> References: <678391342421391@web21g.yandex.ru> Date: Mon, 16 Jul 2012 09:29:52 -0600 Message-ID: From: Anthony Tavener To: Ivan Cc: "caml-list@inria.fr" Content-Type: multipart/alternative; boundary=0016e6d99ee0e9dd9804c4f4195e Subject: Re: [Caml-list] passing object to a function fails to compile (lablgtk2 involved) --0016e6d99ee0e9dd9804c4f4195e Content-Type: text/plain; charset=ISO-8859-1 Hi Ivan, I'm not an OCaml wizard, but I'll hazard a guess... Are your lines calling create_model and fill_model in a different module than where the functions are defined? (or called from the toplevel?) If so, it might be that the types at the module boundary are not constrained enough to be compatible? (apologies if my terminology is incorrect) If these functions are in a different module than the calls to them, you might need to define the module signature, using a consistent type for a "model". Sometimes two types are not equal, even though they *would* amount to the same underlying representation in a particular scenario. So, check the inferred types of your functions... you might need to add another hint to express what you want. When you roll everything into one function, the compiler has more information about how the values are used. ie., Usage provides another constraint for typing. -Tony On Mon, Jul 16, 2012 at 12:49 AM, Ivan wrote: > 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! > > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > > --0016e6d99ee0e9dd9804c4f4195e Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi Ivan, I'm not an OCaml wizard, but I'll hazard a guess...

Are your lines calling create_model and fill_model = in a different module than where the functions are defined? (or called from= the toplevel?) If so, it might be that the types at the module boundary ar= e not constrained enough to be compatible? (apologies if my terminology is = incorrect)

If these functions are in a different module than the c= alls to them, you might need to define the module signature, using a consis= tent type for a "model". Sometimes two types are not equal, even = though they *would* amount to the same underlying representation in a parti= cular scenario. So, check the inferred types of your functions... you might= need to add another hint to express what you want.

When you roll everything into one function, the compile= r has more information about how the values are used. ie., Usage provides a= nother constraint for typing.

=A0-Tony

On Mon, Jul 16, 2012 at 12:49 AM, Ivan <ivg@ieee.org= > wrote:
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 =3D
=A0 let pars =3D P.from_file "parallax.cfg" in
=A0 let add_record (name, value) =3D
=A0 =A0 let iter =3D model#append () in
=A0 =A0 model#set ~row:iter ~column:name_col =A0name;
=A0 =A0 model#set ~row:iter ~column:value_col =A0 value
=A0 in List.iter add_record pars

(where P.from_file some function generating an assoc list -> (string * s= tring) list )

and

let create_model () =3D
=A0 let cols =A0 =3D new GTree.column_list in
=A0 let name_col =A0=3D cols#add Gobject.Data.string
=A0 and value_col =3D cols#add Gobject.Data.string in
=A0 let model =A0=3D GTree.list_store cols in
=A0 (model, name_col, value_col)

When I try to pass values returned by function `create_model' to functi= on `fill_model' with the following expression:

=A0 let model, name_col, value_col =3D create_model () in
=A0 fill_model model name_col value_col

compiler refuses with:

Error: This expression has type GTree.list_store
=A0 =A0 =A0 =A0but an expression was expected of type
=A0 =A0 =A0 =A0 =A0< append : unit -> Gtk.tree_iter;
=A0 =A0 =A0 =A0 =A0 =A0set : row:Gtk.tree_iter -> column:'a -> Ty= pes.id -> unit; .. >
=A0 =A0 =A0 =A0The universal variable 'b would escape its scope

If I write the two functions in one, like this:
let fill_and_create_model () =3D
=A0 let cols =A0 =3D new GTree.column_list in
=A0 let name_col =A0=3D cols#add Gobject.Data.string
=A0 and value_col =3D cols#add Gobject.Data.string in
=A0 let model =A0=3D GTree.list_store cols in
=A0 let pars =3D P.resolve_links (P.from_file "parallax.cfg") in<= br> =A0 let add_record (name, value) =3D
=A0 =A0 let iter =3D model#append () in
=A0 =A0 model#set ~row:iter ~column:name_col =A0name;
=A0 =A0 model#set ~row:iter ~column:value_col "shit"
=A0 in List.iter add_record pars

everything compiles without a notice.

Please, can somebody explain me what I am doing wrong, and what is =A0"= ;universal variable 'b" that escapes from its scope.

Big thanks, in advance for any help!


--
Caml-list mailing list. =A0Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


--0016e6d99ee0e9dd9804c4f4195e--