Loading ...
Sorry, an error occurred while loading the content.

[ANNOUNCE] ECaml 0.2 object system

Expand Messages
  • issac_trotts
    My previous six or so attempts to send this message never appeared on the main OCaml list over the past few days, so now I am trying a workaround. Please
    Message 1 of 2 , Feb 17, 2004
    • 0 Attachment
      My previous six or so attempts to send this message never
      appeared on the main OCaml list over the past few days,
      so now I am trying a workaround. Please don't respond to
      this message on Yahoo, because then it won't make it to the
      main list. Thanks!
      ====

      ECaml defines a simple, type-safe object system within OCaml.
      It is available at

      http://redwood.ucdavis.edu/~issac/software/ecaml-0.2.tar.gz

      Here is an example of how easy ECaml is to use:

      let new_point x y =
      let x = ref x and y = ref y in
      entity
      [ get () -> (!x, !y)
      | set x2 y2 ->
      x := x2;
      y := y2 ];;
      let p = new_point 2 3;;
      let x,y = p:get();;
      p:set (x+1) (y-3);;

      The ECaml syntax for methods with polymorphic arguments is simple:

      let joe = entity [ mymethod x -> x ];;
      joe:mymethod 3;;
      joe:mymethod "foo";;

      It is also easy to define entities (ECaml objects) that refer to
      themselves, since entities are just functions:

      let rec joe =
      entity
      [ getself () -> joe
      | sendself other -> other:receive joe ];;
      let receiver =
      entity
      [ receive thing ->
      let x = thing:getself() in
      () ];;
      joe:getself();;
      joe:sendself receiver;;

      ECaml can simulate multiple inheritance:

      let new_base1 x =
      let x = ref x in entity [ method_a () -> incr x; !x ];;
      let new_base2 () =
      entity [ method_b () -> prerr_endline "method b" ];;
      let new_derived x =
      let b1 = new_base1 x in
      let b2 = new_base2 () in
      entity [ method_a -> b1:method_a | method_b -> b2:method_b ];;

      ECaml can also do some things that the OCaml object system cannot:

      - create objects of anonymous class
      - create new classes within functions or other classes

      Enjoy,
      -ijt
    Your message has been successfully submitted and would be delivered to recipients shortly.