Version française
Home     About     Download     Resources     Contact us    
Browse thread
Does LablTk have a future?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: yoann padioleau <padator@w...>
Subject: Re: GUI for OCaml (was: Re: [Caml-list] Does LablTk have a future?)
>>
>>> I'm not even sure what a "functional" API for a
>>> GUI toolkit would look like.  Ideas?  Example code snippets?
>>>

In fact the API is already "functional" in some way, because in ocaml
(as well as in perl, ruby, ...) you can pass closure as callbacks.  
This is something really great for GUI compared
to langage like C where you have to separate the code responsible for  
creation of the widget from
the code responsible for the action on the widget.

Another point is that it is functional because you can compose the  
widgets together. You can nest them so the nesting of the code
can be put in paralell with the nesting in the widgets.

You can do

build_app_widget(title: "myapp",
      (build_vbox
        (build_menu
           (build_item "File" callback:(fun () -> some_action))
           (build_item "Close"  callback:(fun () -> some_other_action)
      ...
     )
     (build_hbox
       (build_canvas
         (...
      )
   ...
  )



>>
>> I think the GUI code should be split into definition (i.e. how the  
>> widgets are
>> laid out) and execution (i.e. what functions are called for GUI  
>> events). The
>> former should be functional in style because it is easier to write  
>> and more
>> succinct and the latter should be imperative in style because it is
>> essentially poking a state machine about.
>>
>
> This sounds like QTk.  It is a wrapper to Tk that uses records (tuples
> and atoms are records in Oz) and call backs to implement the gui.
> It's quite effective.  In Oz, your example would look something like
> this... (warning, last Oz use was a while ago)
>
> Qtk.build td(lr(label:"Search" text(handle: H))
>                  (lr(button(text:"Add" action:P)
>
> Where P and H are call back procedures.
>

 From what I remember you can do exactly the kind of stuff you wrote  
with lablgtk quite easily.

The only problem is that many times in H and P you want to modify the  
state of the widget (for instance modify the text in an entry) and in  
that
case you have to name the widget  with a let.


>
> Make it independant to a degree.  Most GUIs offer the same  
> functionality anyway.
>


I agree.

>
> Chris
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>