CoNNeTTivo
Ritorna al Sommario

Arte e Grafica

Arte In Movimento

Auto-aiuto informatico

CDA Anomalia

Comunicoscopio

CoNNeTTivo

Gr(A)fismo

Ocamlearn

Radar di Pace
Ocamlearn
Q&A: Types for classes
venerdì 7 marzo 2003





NELLA STESSA RUBRICA :
>7 marzo 2003
>5 marzo 2003
PAROLE CHIAVE ASSOCIATE :





ARTICOLI CON LO STESSO TEMA :


Question

What type is: < as_widget : ’a Gtk.obj; .. > ? Does it mean an object belonging to a class where a method as_widget is defined?

Answer

Precisely: each time you define a class you define various things for the ocaml environment, one of this thing is a type which you can think as a "row" of pairs <method_name, method_type>. The trailing ".." means stands for "other methods". In your example the the type means "an object which has _at_least_ a method named "as_widget" whose type is "’a Gtk.obj" but the object may also have other methods. You can use that object every time you need instance on which invoke the "as_widget" method.

You can see something similar here:

# let f o = o#foo + 1;;
val f : < foo : int; .. > -> int = <fun>

where you are defining a function "f" which takes an object "o" and invokes on it method "foo" which must have type "int". The type system correctly infers that the type of "o" is "<foo: int; .. >".

© Stefano ’’Zack’’ Zacchiroli GNU FDL 2003

CoNNeTTivo   



© 2003 realizzato e concepito da ernestor + arlok + oSi + Z.
Questo sito usa PHP e mySQL ed è realizzato con software in licenza GNU/GPL.
Tutti i testi contenuti in questo sito sono COPYRIGHT dei loro autori.

fil XML