Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* Polymorphic map and OO syntax extension
@ 2005-07-09  3:59 Jacques Garrigue
  2005-07-15  1:41 ` [Caml-list] " Marc Lasson
  0 siblings, 1 reply; 4+ messages in thread
From: Jacques Garrigue @ 2005-07-09  3:59 UTC (permalink / raw)
  To: caml-list

Hello camlers,

I've just put together some code bits I thought my be interesting for
others.

You can find them at
  http://www.math.nagoya-u.ac.jp/~garrigue/code/ocaml.html

OO syntax extension
    Some camlp4 syntax extensions to write more compact code using
    objects. The new syntaxes are
        * val [mutable] x = expr with (reader|writer|accessor)
          generates code for an x and a set_x method, like in ruby.
        * obj#x <- expr
          generates a call to the set_x method.
        * {| [mutable] f1 = expr1; ...; [mutable] fn = exprn |}
          generates an immediate object with the above fields and the
          corresponding accessor methods. You may also include inherit
          declarations.  

Polymap
    This is a tiny module combined with a camlp4 extension, which
    allows you to define polymorphic mappings, where the type of the
    data depends on the key. (The syntax is strange, but I had no
    better idea.)
        $ ocaml camlp4o.cma pa_polymap.cmo polymap.cmo
        # let m = `{x=1; y=true};;
        val   m : [> `x of int | `y of bool ] Polymap.t = 
        # let m = `{m with z = "hello"};;
        val m : [> `x of int | `y of bool | `z of string ] Polymap.t = 
        # m.`y;;
        - : bool = true
        # `{m with x = "a"};;
            ^
        Types for tag `x are incompatible
        # m.`u;;
        Exception: Not_found.

---------------------------------------------------------------------------
Jacques Garrigue      Nagoya University     garrigue at math.nagoya-u.ac.jp
		   <A HREF=http://www.math.nagoya-u.ac.jp/~garrigue/>JG</A>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-07-15  4:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-09  3:59 Polymorphic map and OO syntax extension Jacques Garrigue
2005-07-15  1:41 ` [Caml-list] " Marc Lasson
2005-07-15  2:40   ` Jacques Garrigue
2005-07-15  4:10   ` Martin Jambon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox