1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 %deffont "code" xfont "itc avant garde gothic-demi-r", tfont "verdana.ttf"
3 %deffont "code-bold" xfont "terminal-bold-r", tfont "verdanab.ttf"
4 %deffont "sans" xfont "helvetica-medium-r", tfont "comic.ttf"
5 %deffont "sans-bold" xfont "helvetica-bold-r", tfont "comicbd.ttf"
6 %deffont "sansit" xfont "helvetica-medium-i", tfont "marlett.ttf"
7 %deffont "title" xfont "times-medium-r", tfont "times.ttf"
8 %deffont "title-bold" xfont "times-bold-r", tfont "timesbd.ttf"
9 %default 1 right, size 2, fore "white", bgrad
10 %default 1 vfont "goth", font "sans-bold", vgap 100
11 %default 2 leftfill, size 8, vgap 60, prefix " ", font "sans"
12 %default 3 size 4, bar "beige", vgap 10
13 %default 4 size 5, fore "white", vgap 20, prefix " "
14 %tab 1 size 5, vgap 40, prefix " ", icon box "green" 50
15 %tab 2 size 5, vgap 40, prefix " ", icon arc "yellow" 50
16 %tab 3 size 5, vgap 40, prefix " ", icon arc "white" 40
17 %tab com1 size 4, prefix " "
18 %tab com2 size 4, prefix " "
19 %tab com3 size 4, prefix " "
20 %tab txt font "sans", size 5, fore "white", prefix " "
22 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25 %size 9, font "title-bold"
26 %fore "beige", back "navyblue", vgap 20
30 A Type System in Action:
39 garrigue@kurims.kyoto-u.ac.jp
41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 Objective Label introduction
50 GTK+/LablGTK structure
54 Type encoding with variants
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71 Based on Objective Caml
72 ML syntax and type inference
73 Class-based object system
76 Labeled and optional parameters
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89 %font "code", size 4, prefix " ", fore "yellow"
90 let rec map fun:f = function
92 | x :: l -> f x :: map fun:f l
94 val map : fun:('a -> 'b) -> 'a list -> 'b list
96 %pause, fore "yellow", font "code"
99 val f : fun:(int -> 'a) -> 'a list
103 - : int list = [2; 3; 4]
105 %pause, fore "yellow", font "code"
106 let f x ?incr:y [< 1 >] = x + y
108 val f : int -> ?incr:int -> int
114 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120 %font "code", size 4, prefix " ", fore "yellow"
123 - : [> off on] list = [`on; `off]
125 %pause, fore "yellow", font "code"
128 - : [> number(int)] = `number 1
130 %pause, fore "yellow", font "code"
131 let f = function `on -> 1 | `off -> 0 | `number n -> n
133 val f : [< number(int) off on] -> int
135 %pause, fore "yellow", font "code"
136 type t = [on off number(int)]
138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
143 Not allowed in Objective Caml
146 %font "code", size 4, prefix " ", fore "yellow"
147 class c = object method m x = x end
149 Some type variables are unbound in this type:
150 class c : object method m : 'a -> 'a end
151 The method m has type 'a -> 'a where 'a is unbound
153 %pause, font "sans", size 5, prefix " ", fore "white"
154 Need explicit annotation in O'Labl
157 %font "code", size 4, prefix " ", fore "yellow"
159 method m : 'a. 'a -> 'a = fun x -> x
162 class c : object method m : 'a -> 'a end
170 - : int * bool = 1, true
172 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
177 Why use the GIMP Tool Kit?
180 Widely used in free software
183 Written in C (QT uses C++)
189 Design lacks uniformity
190 Extensive use of dynamic typing
192 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
197 Class hierarchy based on GtkObject
201 &com1 New widgets may redefine methods
205 &com1 Casting necessay both up and down
208 Developper-side hierarchy
209 &com1 Inheritance is not always meaningful to the user
213 Signal-based callback mechanism
216 May use multiple callbacks
219 Signals are polymorphic
221 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
231 C stub functions -- typechecked by C
233 ML type declarations -- ML abstract types
238 ML class wrappers -- ML concrete types
240 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247 Strongly typed interface
248 &com1 heavy use of advanced typing techniques
251 &com1 C-stubs and external declarations
253 Safe memory management
254 &com1 have the library cooperate with the GC
256 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
259 Low level encoding (I)
262 How to represent widget subtyping in ML?
264 Example: buttons' hierarchy
267 %font "code", size 5, prefix " ", fore "yellow"
275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
278 Variants as set constraints
281 Variants can be seen as sets of possible values:
283 [tag1 ... tagn] = {tag1,...,tagn}
286 Polymorphic variants introduce constraints
288 \e$B&A
\e(B[> tag1 ... tagn]
\e$B"N
\e(B
\e$B&A
\e(B
\e$B"?
\e(B {tag1,...,tagn}
289 \e$B&A
\e(B[< tag1 ... tagn]
\e$B"N
\e(B
\e$B&A
\e(B
\e$B">
\e(B {tag1,...,tagn}
291 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
296 Define an abstract type
298 %font "code", fore "yellow", size 5
301 &txt Use tags to represent properties
303 %font "code", fore "yellow", size 5
304 type t = [class1 ... classn] obj
306 &txt Functions check properties
308 %font "code", fore "yellow", size 5
309 val f : [> class1 ... classn] obj -> ...
311 Subsumes Haskell type classes
313 Allows multiple inheritance
315 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
318 Low level encoding (II)
320 Example: buttons' hierarchy
323 %font "code", size 4, prefix " ", fore "yellow"
325 type widget = [widget] obj
326 type container = [widget container] obj
327 type button = [widget container button] obj
328 type toggle_button = [widget ... togglebutton] obj
329 type radio_button = [widget ... radiobutton] obj
330 type state_type = [ NORMAL
331 ACTIVE PRELIGHT SELECTED INSENSITIVE ]
332 val set_state : [> widget] obj -> state_type -> unit
333 val children : [> container] obj -> [widget] obj list
334 val clicked : [> button] obj -> unit
335 val set_group : [> radiobutton] obj -> group -> unit
337 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
342 Use only standard ML features
345 %font "code", size 4, prefix " ", fore "yellow", vgap 50
350 type state_type = NORMAL | ACTIVE | ... | INSENSITIVE
351 val set_state : 'a widget obj -> state_type -> unit
353 'a container widget obj -> unit widget obj list
354 val clicked : 'a button container widget obj -> unit
357 No multiple inheritance
358 Not very intuitive for the user
360 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
363 Low level encoding (III)
365 Use of labeled parameters
368 %font "code", size 4, prefix " ", fore "yellow", vgap 50
370 value:float -> lower:float -> upper:float ->
371 step_incr:float -> page_incr:float ->
372 page_size:float -> adjustment obj
377 %font "code", size 4, prefix " ", fore "yellow", vgap 50
378 type ('a,'b) signal =
379 { name: string; marshaller: 'b -> GtkArgv.t -> unit }
380 val connect : 'a obj -> sig:('a,'b) signal ->
381 callback:'b -> ?after:bool -> id
382 val button_clicked : ([> button], unit -> unit) signal
384 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
392 Name space is scattered
393 &com1 One has to know in which superclass a function is defined
394 Developper oriented design
395 &com1 There is no clear distinction between public and private definitions
400 OCaml classes to reunify name space
401 Omit developper-oriented methods
403 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
408 %font "code", size 4, prefix " ", fore "yellow"
417 ?packing:(GButton.button -> unit) ->
422 method destroy : unit -> unit
423 method as_widget : Gtk.widget obj
424 method misc : GObj.widget_misc
426 method add : #is_widget -> unit
427 method set_border_width : int -> unit
429 method clicked : unit -> unit
430 method connect : GButton.button_signals
431 method grab_default : unit -> unit
435 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
440 Objective Caml classes
441 &com1 allow collecting methods from different modules
443 Use optionals in class constructors
444 &com1 makes widget creation much easier
447 &com1 needed for container widgets
450 %font "code", size 4, fore "yellow", vgap 50
451 method add : 'a. (#is_widget as 'a) -> unit
453 %fore "white", font "sans"
455 &com1 for C-style enumeration types, avoid name-space dependancies
457 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
460 Polymorphic methods (I)
462 Instance of first-class polymorphism
465 first-class polytypes cannot be inferred
466 they are propagated by the definition flow
471 use polymorphism to track available information
472 type system excludes derivations based on "guessed" information
475 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
478 First class polymorphism
481 %image "formula.eps" 512x384
484 %prefix " ", size 5, fore "lightblue"
485 (
\e$B&R
\e(B1 :
\e$B&R
\e(B :
\e$B&R
\e(B2)
\e$B"N
\e(B
\e$B&R
\e(B1 =
\e$B&H
\e(B(
\e$B&Q
\e(B1(
\e$B&R
\e(B))
\e$B"J
\e(B
\e$B&R
\e(B2 =
\e$B&H
\e(B(
\e$B&Q
\e(B2(
\e$B&R
\e(B))
487 where
\e$B&H
\e(B instantiates free variables, and
\e$B&Q
\e(B1,
\e$B&Q
\e(B2 rename free labels of
\e$B&R
\e(B.
489 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
492 Polymorphic methods (II)
497 %font "code", size 4, prefix " ", fore "yellow", vgap 50
498 type is_widget = < as_widget : widget obj >
499 type #is_widget = < as_widget : widget obj; .. >
501 < ... ; add : 'a. (#as_widget as 'a) -> unit; ... >
507 %font "code", size 4, prefix " ", fore "lightgreen", vgap 50
508 fun (cont : container) -> cont#add widget
511 let button = new button in button#add widget
514 fun cont -> cont#add widget
516 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
524 %font "code", size 4, prefix " ", fore "yellow"
528 new GWindow.window border_width: 10
532 label: "Hello World" packing: window#add
535 window#connect#destroy callback: Main.quit;
536 button#connect#clicked callback: window#destroy;
540 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
548 Could build a strongly typed interface
550 It is easier to use than the C API
552 Makes effective use of extensions to the type system
557 Still difficulties with the Caml object system
558 &com2 class recursion, method type refinement, etc...