Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: mattias@fforum.se
Cc: caml-list@inria.fr
Subject: Re: Typing problems when using LablGTK
Date: Mon, 05 Feb 2001 12:05:05 +0900	[thread overview]
Message-ID: <20010205120505T.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <200102032154.f13LsK116451@fforum.se>

Hello Mattias,

> The first program works fine, but if I take the let button-part and
> move it to a separate function called mini, the compilation fails.
> The type of the method attach is different.
> 
> What have I misunderstood?

Your problem is explained in the tutorial (1st part of the reference
manual) in section 2.1.3. To be correctly handled, labeled and
optionals arguments need to be known at the application point.  If you
move this application out of its context, the type information is
lost, and an incorrect type is inferred.

The standard solution is to add a type annotation on objects whose
methods have optional arguments:

let mini (table : GPack.table) =
  GButton.button ~label:"mini"
    ~packing:(table#attach ~left:3 ~top:3 ~expand:`BOTH) ();
  ()

> /mattias
> 
> P.s. I learning GNOME using the book "Beginning GTK+/GNOME
> Programming", and sometimes it is difficult to map GTK in C to
> LablGTK. I am on page 111.

While the relation is kept intuitive, there are indeed differences
between GTK and LablGTK. Otherwise you wouldn't be able to write much
shorter programs :-) If you really don't know how to translate, the
low-level interface gives access to the raw calls, but this is much
less comfortable.

> Program 2, fails
> ================
> 
> open GMain
> 
> let mini table : unit =
>   GButton.button ~label:"mini"
>     ~packing:(table#attach ~left:3 ~top:3 ~expand:`BOTH) ();
>   ()
> 
>   
> let main () =
>   let window = GWindow.window ~border_width:10 ~title:"Fun with tables" ~width:320 ~height:200 () in
>   window#connect#destroy ~callback:Main.quit; 
>   let table = GPack.table ~rows:10 ~columns:10 ~packing:window#add () in
>   mini table; 
>   window#show ();
>   Main.main ()
> 
> let _ = Printexc.print main ()



  parent reply	other threads:[~2001-02-05 16:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-02-03 21:54 Mattias Waldau
2001-02-04 23:09 ` Maxence
2001-02-05  3:05 ` Jacques Garrigue [this message]
2001-02-05 18:18   ` Mattias Waldau
2001-02-06  1:58     ` Jacques Garrigue

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=20010205120505T.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=mattias@fforum.se \
    /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