Re: CamlTk and LablTk

From: Pierre Weis (Pierre.Weis@inria.fr)
Date: Sat Jun 03 2000 - 10:16:05 MET DST

  • Next message: Julian Assange: "fftw"

    > (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/



    This archive was generated by hypermail 2b29 : Sat Jun 03 2000 - 11:01:42 MET DST