* syntax changes from 3.08 to 3.10
@ 2007-07-11 10:10 Sebastien Ferre
2007-07-11 11:28 ` [Caml-list] " Nicolas Pouillard
0 siblings, 1 reply; 2+ messages in thread
From: Sebastien Ferre @ 2007-07-11 10:10 UTC (permalink / raw)
To: caml-list; +Cc: Sébastien Ferre
Hi,
moving my application from OCaml 3.08 to 3.10,
I encountered 2 syntax problems, i.e. syntax errors
when compiling:
1. record copy and modification:
{f x with y = 1; z = 2}
this can be solved by parenthesizing the
evaluation of the record to be copied.
{(f x) with y = 1; z = 2}
2. object copy and modification in a method:
{< x = 1; y = 2>}
OCaml says the first field is a bool instead of an int,
which leads me to think it parenthesizes in the following way:
{< x = (1; y = 2)>}
In fact, this behaviour is only when compiling with camlp4o:
ocamlc -pp ocamlp4o ...
The work-around I found to implement a copy method is as follows:
class c =
object (self)
val x = 0
val y = 0
method copy = (Oo.copy self) # copy_aux
method private copy_aux = x <- 1; y <- 2; self
end
Has anybody encountered the same problem ? Is there a better workaround
? Is it a bug ?
Sébastien
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] syntax changes from 3.08 to 3.10
2007-07-11 10:10 syntax changes from 3.08 to 3.10 Sebastien Ferre
@ 2007-07-11 11:28 ` Nicolas Pouillard
0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Pouillard @ 2007-07-11 11:28 UTC (permalink / raw)
To: Sebastien Ferre; +Cc: caml-list
On 7/11/07, Sebastien Ferre <ferre@irisa.fr> wrote:
> Hi,
>
> moving my application from OCaml 3.08 to 3.10,
> I encountered 2 syntax problems, i.e. syntax errors
> when compiling:
>
> 1. record copy and modification:
>
> {f x with y = 1; z = 2}
>
> this can be solved by parenthesizing the
> evaluation of the record to be copied.
>
> {(f x) with y = 1; z = 2}
Yes you now have to put these parentheses.
> 2. object copy and modification in a method:
>
> {< x = 1; y = 2>}
>
> OCaml says the first field is a bool instead of an int,
> which leads me to think it parenthesizes in the following way:
>
> {< x = (1; y = 2)>}
>
> In fact, this behaviour is only when compiling with camlp4o:
>
> ocamlc -pp ocamlp4o ...
Yes that's an awful bug that is already fixed in CVS.
>
> The work-around I found to implement a copy method is as follows:
>
> class c =
> object (self)
> val x = 0
> val y = 0
>
> method copy = (Oo.copy self) # copy_aux
> method private copy_aux = x <- 1; y <- 2; self
> end
>
>
> Has anybody encountered the same problem ? Is there a better workaround
> ? Is it a bug ?
>
A better workaround is:
class c =
object (self)
val x = 0
val y = 0
method set_x newx = {< x = newx >}
method set_y newy = {< y = newy >}
method copy = (self#set_x 1)#set_y 2
end
But this camlp4 bug is very nasty (perhaps you can try to move these
calls in a file that does not require camlp4o)
--
Nicolas Pouillard
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-07-11 11:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-11 10:10 syntax changes from 3.08 to 3.10 Sebastien Ferre
2007-07-11 11:28 ` [Caml-list] " Nicolas Pouillard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox