version francaise

COCA-ML

coca-ml is a small extension to ocaml 3-02 using camlp4 3.02 to allow "down cast" of objects between classes in relations of inheritence and sub-typing.

Warning there was a bug inside the version 0.1c (see Changes). To correct it the new version 0.1d has several important changes.




The main idea is to allow an "upcast" only at one level inside the inheritence tree to check the sub-typing relation.

Description

This extension introduces three new syntatic constructions :
"instance of" "upcast" "downcast"
Syntax expr instanceof c upcast var from c1 to c2 downcast var from c1 to c2
Typing bool c2 c2
Evaluation true or false value of var value of var

Semantics and implementation

o instanceof c1
semantic implementation
1. o "is-a" c1 ( Cast.check loc o key_c1)

upcast o from c1 to c2
semantic implementation
1. o is exactly an instance of c1

and c1 inherits directly from c2

Cast.check_sonof var c1 c2
2. type of var is a sub-type of c2 ( var :> c2)

1/ is at running level
2/ is at running level

downcast o from c1 to c2
semantic implementation
1. o has type c1 ( o : c1)
2. c2 is a sub-type of c1 ( c2 :> c1)
3. o "is-a" c1 ( Cast.check loc o key_c1)
4. o "is-a" c2 ( Cast.check loc o key_c2)
5. ((Obj.magic o) : c2)

1/ and 2/ are at typing level
3/ and 4/ are at running level


Examples

There are more complete examples in the distribution.

Changes


Distribution

distribution : cocaml-0.1d.tar

ocaml : O'Caml 3.02

camlp4 : camlp4 3.02


Updating : 28/09/2001