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

* Re: [Caml-list] OO syntax extension
  2005-07-09  3:59 Polymorphic map and OO syntax extension Jacques Garrigue
@ 2005-07-15  1:41 ` Marc Lasson
  2005-07-15  2:40   ` Jacques Garrigue
  2005-07-15  4:10   ` Martin Jambon
  0 siblings, 2 replies; 4+ messages in thread
From: Marc Lasson @ 2005-07-15  1:41 UTC (permalink / raw)
  To: caml-list

Jacques Garrigue wrote:

>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.  
>
I am very interested in your OO syntax extension but i did not succeed 
to compile it.
I get the following error:

marc@georgie:~$ ocamlc -I +camlp4 -c -pp 'camlp4o pa_extend.cmo 
q_MLast.cmo' pa_oo.ml
File "pa_oo.ml", line 12, characters -249--249:
Unbound value loc

The error's position looks very weird. Since i can't speak camlp4, i'm 
unable to fix it.
Is it serious doctor ?

-- 
Marc Lasson.


marc@georgie:~$ ocamlc -v && camlp4o -v
The Objective Caml compiler, version 3.08.2
Standard library directory: /usr/lib/ocaml/3.08
Camlp4 version 3.08.2


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

* Re: [Caml-list] OO syntax extension
  2005-07-15  1:41 ` [Caml-list] " Marc Lasson
@ 2005-07-15  2:40   ` Jacques Garrigue
  2005-07-15  4:10   ` Martin Jambon
  1 sibling, 0 replies; 4+ messages in thread
From: Jacques Garrigue @ 2005-07-15  2:40 UTC (permalink / raw)
  To: titmarc; +Cc: caml-list

From: Marc Lasson <titmarc@free.fr>

> I am very interested in your OO syntax extension but i did not succeed 
> to compile it.
> I get the following error:
> 
> marc@georgie:~$ ocamlc -I +camlp4 -c -pp 'camlp4o pa_extend.cmo 
> q_MLast.cmo' pa_oo.ml
> File "pa_oo.ml", line 12, characters -249--249:
> Unbound value loc
> 
> The error's position looks very weird. Since i can't speak camlp4, i'm 
> unable to fix it.
> Is it serious doctor ?
> 
> marc@georgie:~$ ocamlc -v && camlp4o -v
> The Objective Caml compiler, version 3.08.2
> Standard library directory: /usr/lib/ocaml/3.08
> Camlp4 version 3.08.2

Simplest fix: upgrade to 3.08.3.
"loc" was changed to "_loc" between 3.08.2 and 3.08.3.
You can also replace all occurrences of "_loc" in the source by "loc".

Jacques Garrigue


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

* Re: [Caml-list] OO syntax extension
  2005-07-15  1:41 ` [Caml-list] " Marc Lasson
  2005-07-15  2:40   ` Jacques Garrigue
@ 2005-07-15  4:10   ` Martin Jambon
  1 sibling, 0 replies; 4+ messages in thread
From: Martin Jambon @ 2005-07-15  4:10 UTC (permalink / raw)
  To: Marc Lasson; +Cc: caml-list

On Fri, 15 Jul 2005, Marc Lasson wrote:

> Jacques Garrigue wrote:
>
> >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.
> >
> I am very interested in your OO syntax extension but i did not succeed
> to compile it.
> I get the following error:
>
> marc@georgie:~$ ocamlc -I +camlp4 -c -pp 'camlp4o pa_extend.cmo
> q_MLast.cmo' pa_oo.ml
> File "pa_oo.ml", line 12, characters -249--249:
> Unbound value loc
>
> The error's position looks very weird. Since i can't speak camlp4, i'm
> unable to fix it.

Pass the -loc _loc option to camlp4o and it should work.
See http://martin.jambon.free.fr/extend-ocaml-syntax.html#loc


Martin

--
Martin Jambon, PhD
http://martin.jambon.free.fr



^ 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