caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* CamlTk and LablTk
@ 2000-05-18 17:37 Georges MARIANO
  2000-05-22 14:57 ` Pierre Weis
  0 siblings, 1 reply; 4+ messages in thread
From: Georges MARIANO @ 2000-05-18 17:37 UTC (permalink / raw)
  To: caml-list

Hello everyone,

very short question :

How can we compare camltk and labltk ??
(functionalities, ease of writing (complex) GUI, portability,
integration in Ocaml-3.00,  ...)

I know that this question would result in a flame war but I
hope that we can be smart enough to avoid it ;-)
Just help the puzzled user please...

-- 
> Georges MARIANO                 tel: (33) 03 20 43 84 06
> INRETS, 20 rue Elisee Reclus    fax: (33) 03 20 43 83 59
> 59650 Villeneuve d'Ascq         mailto:mariano@terre.inrets.fr
> FRANCE.                         
> http://www3.inrets.fr/Public/ESTAS/Mariano.Georges/
> http://www3.inrets.fr/BUGhome.html         mailto:Bforum@estas1.inrets.fr




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: CamlTk and LablTk
  2000-05-18 17:37 CamlTk and LablTk Georges MARIANO
@ 2000-05-22 14:57 ` Pierre Weis
  0 siblings, 0 replies; 4+ messages in thread
From: Pierre Weis @ 2000-05-22 14:57 UTC (permalink / raw)
  To: Georges MARIANO; +Cc: caml-list

> How can we compare camltk and labltk ??
> (functionalities, ease of writing (complex) GUI, portability,
> integration in Ocaml-3.00,  ...)
[...]
> > 59650 Villeneuve d'Ascq         mailto:mariano@terre.inrets.fr

There is no reason to start a flameware on this subject :)

In short: both libraries have comparable functionality, CamlTk being
based on the core Caml language to interface Tk (with the drawback of
some sort of dynamic type checking), while LablTk uses a set of new
powerful features to ensure a strictly static type-checking (with no
drawback, except that you have to know how to use the new features to
write your GUI with the library).

In some details:

- functionality is somewhat equivalent, since both libraries are
derived from the same ``Widget compiler'' interfacing Caml to the Tk
library.

- ``ease of writing (complex) GUI'' is questionable since:
  - LablTk has undoubtedly a better type system for Tk options that
    are now statically checked, whereas options are checked dynamically
    with CamlTk (hence more errors are statically detected with
    LablTk).
 
  - CamlTk is simpler since it does not use labels, options and
    polymorphic variants.

- portability: both libraries seem equally portable (?)

- integration in Ocaml-3.00: LablTk is distributed with O'Caml V3.0
  and uses the newest features of the language. CamlTk is distributed
  separately and uses the core language only.

To give an idea of the difference between the two libraries, here is a
small example due to June Furuse (the example mimicks Xeyes) given in
the two styles:

(* The eyes of Caml (CamlTk style) *)
(* ocamlc -custom -I /usr/local/lib/ocaml/camltk41 -o tetris tk41.cma tetris.ml *)

open Tk

let _ =
  let top = openTk () in
  let fw = Frame.create top [] in
  pack [fw] [];
  let c = Canvas.create fw [Width (Pixels 200); Height (Pixels 200)] in
  let create_eye cx cy wx wy ewx ewy bnd =
    let o2 =
       Canvas.create_oval c
        (Pixels (cx - wx)) (Pixels (cy - wy))
        (Pixels (cx + wx)) (Pixels (cy + wy))
        [Outline (NamedColor "black"); Width (Pixels 7);
         FillColor (NamedColor "white")]
    and o =
      Canvas.create_oval c
       (Pixels (cx - ewx)) (Pixels (cy - ewy))
       (Pixels (cx + ewx)) (Pixels (cy + ewy))
       [FillColor (NamedColor "black")] in
    let curx = ref cx
    and cury = ref cy in
    bind c [[], Motion]
      (BindExtend ([Ev_MouseX; Ev_MouseY],
        (fun e ->
          let nx, ny =
            let xdiff = e.ev_MouseX - cx 
            and ydiff = e.ev_MouseY - cy in
            let diff = sqrt ((float xdiff /. (float wx *. bnd)) ** 2.0 +. 
                               (float ydiff /. (float wy *. bnd)) ** 2.0) in
            if diff > 1.0 then
              truncate ((float xdiff) *. (1.0 /. diff)) + cx,
              truncate ((float ydiff) *. (1.0 /. diff)) + cy
            else
              e.ev_MouseX, e.ev_MouseY
          in
          Canvas.move c o (Pixels (nx - !curx)) (Pixels (ny - !cury));
          curx := nx;
          cury := ny)))
  in
  create_eye 60 100 30 40 5 6 0.6;
  create_eye 140 100 30 40 5 6 0.6;
  pack [c] []

let _ = Printexc.print mainLoop ()


(* The eyes of Caml (LablTk) *)
(* ocamlc -w s -labels -I /usr/local/lib/ocaml/labltk -o tetris labltk.cma tetris.ml *)

open Tk

let _ =
  let top = openTk () in
  let fw = Frame.create top in
  pack [fw];
  let c = Canvas.create ~width: 200 ~height: 200 fw in
  let create_eye cx cy wx wy ewx ewy bnd =
    let o2 = Canvas.create_oval
        ~x1:(cx - wx) ~y1:(cy - wy)
        ~x2:(cx + wx) ~y2:(cy + wy) 
        ~outline: `Black ~width: 7
        ~fill: `White
        c
    and o = Canvas.create_oval
        ~x1:(cx - ewx) ~y1:(cy - ewy) 
        ~x2:(cx + ewx) ~y2:(cy + ewy)
        ~fill:`Black
        c in
    let curx = ref cx
    and cury = ref cy in
    bind ~events:[`Motion] ~extend:true ~fields:[`MouseX; `MouseY]
      ~action:(fun e ->
        let nx, ny =
          let xdiff = e.ev_MouseX - cx 
          and ydiff = e.ev_MouseY - cy in
          let diff = sqrt ((float xdiff /. (float wx *. bnd)) ** 2.0 +. 
                             (float ydiff /. (float wy *. bnd)) ** 2.0) in
          if diff > 1.0 then
            truncate ((float xdiff) *. (1.0 /. diff)) + cx,
            truncate ((float ydiff) *. (1.0 /. diff)) + cy
          else 
            e.ev_MouseX, e.ev_MouseY
        in
        Canvas.move c o ~x: (nx - !curx) ~y: (ny - !cury);
        curx := nx;
        cury := ny)
      c
  in
  create_eye 60 100 30 40 5 6 0.6;
  create_eye 140 100 30 40 5 6 0.6;
  pack [c] 

let _ = Printexc.print mainLoop ()

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://cristal.inria.fr/~weis/




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: CamlTk and LablTk
  2000-06-01 16:44 Dave Berry
@ 2000-06-03  8:16 ` Pierre Weis
  0 siblings, 0 replies; 4+ messages in thread
From: Pierre Weis @ 2000-06-03  8:16 UTC (permalink / raw)
  To: Dave Berry; +Cc: caml-list

> (I hope you don't mind me replying to a fairly old message).
> 
> This was a very interesting question, and the examples that Pierre included
> were illuminating.  Would it be possible to elucidate a little further?  In
> particular, I'd appreciate it if someone could give the types of the
> relevant functions in each library.  (At some point one has to look at the
> documentation for all the details, but this seems like a reasonably
> educational example to take a little further).
> 
> Let's compare the two calls to create_oval.  First the Caml/TK:
>       Canvas.create_oval c
>         (Pixels (cx - wx)) (Pixels (cy - wy))
>         (Pixels (cx + wx)) (Pixels (cy + wy))
>         [Outline (NamedColor "black"); Width (Pixels 7);
>          FillColor (NamedColor "white")]
> Second the Labl/TK:
>     Canvas.create_oval
>         ~x1:(cx - wx) ~y1:(cy - wy)
>         ~x2:(cx + wx) ~y2:(cy + wy) 
>         ~outline: `Black ~width: 7
>         ~fill: `White
> 
> It seems that Labl/TK is using labels in two ways.  First, to have named
> arguments, so that you can see which position is x1, which is y1, etc.
> Second, to handle optional arguments.  Where Caml/TK takes a list of
> attributes, Labl/TK takes extra parameters.  I assume that this is where
> Labl/TK has better type checking.  Does the type of each function list the
> optional parameters that it may take?  : Doesn't this lead to large types
> for each function? (I don't know O'Labl at all well).
> 
> Dave.

You are perfectly right. As an example, we can compare the types of
Canvas.create in both libraries;

In Caml/Tk:
-----------

val create : widget -> options list -> widget
             (* [create p options] creates a new widget with parent p.
                Options are restricted to the widget class subset,
                and checked dynamically. *)

simple, but as mentioned in the documentation, options are restricted
to the widget class and this is not checked statically.

In Labl/Tk:
-----------

val create :
  ?name:string ->
  ?background:color ->
  ?borderwidth:int ->
  ?closeenough:float ->
  ?confine:bool ->
  ?cursor:cursor ->
  ?height:int ->
  ?highlightbackground:color ->
  ?highlightcolor:color ->
  ?highlightthickness:int ->
  ?insertbackground:color ->
  ?insertborderwidth:int ->
  ?insertofftime:int ->
  ?insertontime:int ->
  ?insertwidth:int ->
  ?relief:relief ->
  ?scrollregion:(int * int * int * int) ->
  ?selectbackground:color ->
  ?selectborderwidth:int ->
  ?selectforeground:color ->
  ?takefocus:bool ->
  ?width:int ->
  ?xscrollcommand:(first:float -> last:float -> unit) ->
  ?xscrollincrement:int ->
  ?yscrollcommand:(first:float -> last:float -> unit) ->
  ?yscrollincrement:int ->
  ?yscrollincrement:int ->
  'a widget -> canvas widget
             (* [create p options ?name] creates a new widget with
                parent p and new patch component name.
                Options are restricted to the widget class subset,
                and checked dynamically. *)

Extremely precise typing, informative and useful to know which options
you can use to create a canvas. Note also that ``widget'' is no more a
constant type constructor: it takes an 'a parameter to carry and
reflect its kind. So that options can be (and are) checked statically.

Note also, that we will continue to maintain Caml/Tk because we still
use programs that use it (and text book, and courses that give
examples using Caml/Tk). Moreover, being written in the core language,
it could be simpler to start with when teaching GUI to beginners, and
last but not least, it is also the only GUI for Caml light that we
still support for thousands of students.

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://cristal.inria.fr/~weis/





^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: CamlTk and LablTk
@ 2000-06-01 16:44 Dave Berry
  2000-06-03  8:16 ` Pierre Weis
  0 siblings, 1 reply; 4+ messages in thread
From: Dave Berry @ 2000-06-01 16:44 UTC (permalink / raw)
  To: Pierre Weis; +Cc: caml-list

(I hope you don't mind me replying to a fairly old message).

This was a very interesting question, and the examples that Pierre included
were illuminating.  Would it be possible to elucidate a little further?  In
particular, I'd appreciate it if someone could give the types of the
relevant functions in each library.  (At some point one has to look at the
documentation for all the details, but this seems like a reasonably
educational example to take a little further).

Let's compare the two calls to create_oval.  First the Caml/TK:
      Canvas.create_oval c
        (Pixels (cx - wx)) (Pixels (cy - wy))
        (Pixels (cx + wx)) (Pixels (cy + wy))
        [Outline (NamedColor "black"); Width (Pixels 7);
         FillColor (NamedColor "white")]
Second the Labl/TK:
    Canvas.create_oval
        ~x1:(cx - wx) ~y1:(cy - wy)
        ~x2:(cx + wx) ~y2:(cy + wy) 
        ~outline: `Black ~width: 7
        ~fill: `White

It seems that Labl/TK is using labels in two ways.  First, to have named
arguments, so that you can see which position is x1, which is y1, etc.
Second, to handle optional arguments.  Where Caml/TK takes a list of
attributes, Labl/TK takes extra parameters.  I assume that this is where
Labl/TK has better type checking.  Does the type of each function list the
optional parameters that it may take?  : Doesn't this lead to large types
for each function? (I don't know O'Labl at all well).

Dave.




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2000-06-03  8:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-18 17:37 CamlTk and LablTk Georges MARIANO
2000-05-22 14:57 ` Pierre Weis
2000-06-01 16:44 Dave Berry
2000-06-03  8:16 ` Pierre Weis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).