caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] infix precedence
@ 2002-05-28 15:42 dengping zhu
  2002-05-28 15:54 ` Remi VANICAT
  2002-05-28 16:00 ` John Prevost
  0 siblings, 2 replies; 12+ messages in thread
From: dengping zhu @ 2002-05-28 15:42 UTC (permalink / raw)
  To: Ocaml

Hi, all, I have a question about the precedence of infix in ocaml.
I define a few infixes as follow:

let (^^) x y = ...
let (^+) x y = ...
let (^<) x y = ...

Now how can I define the precedence of them?  At first, I want to use
brackets to solve it, but later I find out it is almost impossible because
there are a lot of recursive functions and combination of these infixes. 

Can you give me any idea?
Thanks a lot!




-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] infix precedence
  2002-05-28 15:42 [Caml-list] infix precedence dengping zhu
@ 2002-05-28 15:54 ` Remi VANICAT
  2002-05-28 16:00 ` John Prevost
  1 sibling, 0 replies; 12+ messages in thread
From: Remi VANICAT @ 2002-05-28 15:54 UTC (permalink / raw)
  To: caml-list

dengping zhu <zhudp@cs.bu.edu> writes:

> Hi, all, I have a question about the precedence of infix in ocaml.
> I define a few infixes as follow:
>
> let (^^) x y = ...
> let (^+) x y = ...
> let (^<) x y = ...
>
> Now how can I define the precedence of them?  At first, I want to use
> brackets to solve it, but later I find out it is almost impossible because
> there are a lot of recursive functions and combination of these infixes. 
>
> Can you give me any idea?

yes, the precedence of an infix in ocaml is driven by its first letter,
so :

let (^^) x y = ...
let (+^) x y = ...
let (<^) x y = ...

will make ^^ have the same precedence than ^,  +^ have the same
precedence than + and so one.

otherwise, camlp4 is the only solution.
-- 
Rémi Vanicat
vanicat@labri.u-bordeaux.fr
http://dept-info.labri.u-bordeaux.fr/~vanicat
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] infix precedence
  2002-05-28 15:42 [Caml-list] infix precedence dengping zhu
  2002-05-28 15:54 ` Remi VANICAT
@ 2002-05-28 16:00 ` John Prevost
  2002-05-28 17:19   ` dengping zhu
  1 sibling, 1 reply; 12+ messages in thread
From: John Prevost @ 2002-05-28 16:00 UTC (permalink / raw)
  To: dengping zhu; +Cc: Ocaml

>>>>> "zd" == dengping zhu <zhudp@cs.bu.edu> writes:

    zd> Hi, all, I have a question about the precedence of infix in
    zd> ocaml.  I define a few infixes as follow:

    zd> let (^^) x y = ...  let (^+) x y = ...  let (^<) x y = ...

    zd> Now how can I define the precedence of them?  At first, I want
    zd> to use brackets to solve it, but later I find out it is almost
    zd> impossible because there are a lot of recursive functions and
    zd> combination of these infixes.

    zd> Can you give me any idea?  Thanks a lot!

The precedence and fixity of the infix is determined by the first character.  This is why most "families" of infixes look like:

^^
+^
<^

rather than

^^
^+
^<

John.
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] infix precedence
  2002-05-28 16:00 ` John Prevost
@ 2002-05-28 17:19   ` dengping zhu
  2002-05-28 18:07     ` John Prevost
  0 siblings, 1 reply; 12+ messages in thread
From: dengping zhu @ 2002-05-28 17:19 UTC (permalink / raw)
  To: John Prevost; +Cc: Ocaml


Thanks for your prompt reply. So, the associativity also the same as the
first character.

Then, I have problems with the following code. In SML, I defined a few
infix as follows:

infixr 4 << >>
infixr 3 &&
infix 2 -- ##
infix 2 wth suchthat return guard
infixr 1 ||
				
I want to convert these code into ocaml. How can find so many different
'first characters'? Because the available characters in ocaml are:

**...            right
*... /... %...   left
+... -...        left
@... ^...        right

Do you have any sugestion?

Thanks a lot!

Dengping


On 28 May 2002, John Prevost wrote:

>>>>>> "zd" == dengping zhu <zhudp@cs.bu.edu> writes:
>
>    zd> Hi, all, I have a question about the precedence of infix in
>    zd> ocaml.  I define a few infixes as follow:
>
>    zd> let (^^) x y = ...  let (^+) x y = ...  let (^<) x y = ...
>
>    zd> Now how can I define the precedence of them?  At first, I want
>    zd> to use brackets to solve it, but later I find out it is almost
>    zd> impossible because there are a lot of recursive functions and
>    zd> combination of these infixes.
>
>    zd> Can you give me any idea?  Thanks a lot!
>
>The precedence and fixity of the infix is determined by the first character.  This is why most "families" of infixes look like:
>
>^^
>+^
><^
>
>rather than
>
>^^
>^+
>^<
>
>John.
>

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] infix precedence
  2002-05-28 17:19   ` dengping zhu
@ 2002-05-28 18:07     ` John Prevost
  2002-05-28 18:16       ` dengping zhu
  0 siblings, 1 reply; 12+ messages in thread
From: John Prevost @ 2002-05-28 18:07 UTC (permalink / raw)
  To: dengping zhu; +Cc: John Prevost, Ocaml

>>>>> "zd" == dengping zhu <zhudp@cs.bu.edu> writes:

    zd> I want to convert these code into ocaml. How can find so many
    zd> different 'first characters'? Because the available characters
    zd> in ocaml are:

    zd> **...  right *... /... %...  left +... -...  left @... ^...
    zd> right

    zd> Do you have any sugestion?

Take a look at section 6.7 of the manual for precedence rules, and
section 6.1 (under the heading "Prefix and infix symbols") for the
list of symbols.  In short, this is the list of all the available
infix symbols, in order of precedence:

!... ?... ~...                          prefix
**...                                   right
*... /... %...                          left
+... -...                               left
@... ^...                               right
=... <... >... |... &... $... %...      left

This means that you might have some trouble with your infix levels,
but there are normally ways to organize things for what you'd like.  I
find, also, that having just a few levels and using parenthesis for
the rest of the time can work quite well.  As you note, using this
style for everything can be painful, but having infixes for only a few
specific things can help immensely.

John.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] infix precedence
  2002-05-28 18:07     ` John Prevost
@ 2002-05-28 18:16       ` dengping zhu
  2002-05-28 18:32         ` Daniel de Rauglaudre
  0 siblings, 1 reply; 12+ messages in thread
From: dengping zhu @ 2002-05-28 18:16 UTC (permalink / raw)
  To: John Prevost; +Cc: Ocaml

Hi, John, thanks for your help.  Hope I could solve it today.
Anyway, I think that Ocaml should support infix as SML.

Dengping


On 28 May 2002, John Prevost wrote:

>>>>>> "zd" == dengping zhu <zhudp@cs.bu.edu> writes:
>
>    zd> I want to convert these code into ocaml. How can find so many
>    zd> different 'first characters'? Because the available characters
>    zd> in ocaml are:
>
>    zd> **...  right *... /... %...  left +... -...  left @... ^...
>    zd> right
>
>    zd> Do you have any sugestion?
>
>Take a look at section 6.7 of the manual for precedence rules, and
>section 6.1 (under the heading "Prefix and infix symbols") for the
>list of symbols.  In short, this is the list of all the available
>infix symbols, in order of precedence:
>
>!... ?... ~...                          prefix
>**...                                   right
>*... /... %...                          left
>+... -...                               left
>@... ^...                               right
>=... <... >... |... &... $... %...      left
>
>This means that you might have some trouble with your infix levels,
>but there are normally ways to organize things for what you'd like.  I
>find, also, that having just a few levels and using parenthesis for
>the rest of the time can work quite well.  As you note, using this
>style for everything can be painful, but having infixes for only a few
>specific things can help immensely.
>
>John.
>
>-------------------
>To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
>Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
>Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] infix precedence
  2002-05-28 18:16       ` dengping zhu
@ 2002-05-28 18:32         ` Daniel de Rauglaudre
  2002-05-28 18:48           ` dengping zhu
  0 siblings, 1 reply; 12+ messages in thread
From: Daniel de Rauglaudre @ 2002-05-28 18:32 UTC (permalink / raw)
  To: Ocaml

Hi,

On Tue, May 28, 2002 at 02:16:12PM -0400, dengping zhu wrote:

> Hi, John, thanks for your help.  Hope I could solve it today.
> Anyway, I think that Ocaml should support infix as SML.

Camlp4

-- 
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] infix precedence
  2002-05-28 18:32         ` Daniel de Rauglaudre
@ 2002-05-28 18:48           ` dengping zhu
  2002-05-28 22:44             ` Daniel de Rauglaudre
  0 siblings, 1 reply; 12+ messages in thread
From: dengping zhu @ 2002-05-28 18:48 UTC (permalink / raw)
  To: Daniel de Rauglaudre; +Cc: Ocaml


I tried camlp4 before. I got the example from the camlp4 tutorial and
modified a little bit. 

The code is as follows:
---------------------------------------------
let gram = Grammar.create (Plexer.make());;
let expr = Grammar.Entry.create gram "expr";;

EXTEND
  expr:
      [ "1" LEFTA [] | "2" LEFTA []];
END;;

let add_infix lev op =
         EXTEND
           GLOBAL: expr;
           expr: LEVEL $lev$
            [ [ x = expr; $op$; y = expr -> <:expr< $lid:op$ $x$ $y$ >> ] ];
         END;;
-------------------------------------------------------------------

After I compile it in ocaml 

# #use "foo.ml";;

I can use the function 'add_infix':
# add_infix "1" "op1";;

But how can I use the infix "op1" later? 
I tried to use as follows:

#let op1 x y = x + y;;
#Grammar.Entry.parse expr ( Stream.of_string "x op1 y");;

But I got an error. 

Can someboday pass an example for me?

Thanks!




On Tue, 28 May 2002, Daniel de Rauglaudre wrote:

>Hi,
>
>On Tue, May 28, 2002 at 02:16:12PM -0400, dengping zhu wrote:
>
>> Hi, John, thanks for your help.  Hope I could solve it today.
>> Anyway, I think that Ocaml should support infix as SML.
>
>Camlp4
>
>-- 
>Daniel de RAUGLAUDRE
>daniel.de_rauglaudre@inria.fr
>http://cristal.inria.fr/~ddr/
>-------------------
>To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
>Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
>Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] infix precedence
  2002-05-28 18:48           ` dengping zhu
@ 2002-05-28 22:44             ` Daniel de Rauglaudre
  2002-05-29  2:48               ` dengping zhu
  0 siblings, 1 reply; 12+ messages in thread
From: Daniel de Rauglaudre @ 2002-05-28 22:44 UTC (permalink / raw)
  To: Ocaml

Hi,

On Tue, May 28, 2002 at 02:48:42PM -0400, dengping zhu wrote:
> 
> I tried camlp4 before. I got the example from the camlp4 tutorial and
> modified a little bit. 

Your code cannot work: you are defining a new entry, you are not using
the entry of OCaml expressions, which is Pcaml.expr.

  $ cat foo.ml
  let add_infix lev op =
  EXTEND
    GLOBAL: Pcaml.expr;
    Pcaml.expr: LEVEL $lev$
      [ [ x = SELF; $op$; y = SELF -> <:expr< $lid:op$ $x$ $y$ >> ] ];
  END;;
  $ ocaml
	  Objective Caml version 3.04+11 (2002-05-16)
  
  # #load "camlp4o.cma";;
	  Camlp4s Parsing version 3.04+11
  
  # #load "pa_extend.cmo";;    
  # #load "q_MLast.cmo";;  
  # #use "foo.ml";;
  val add_infix : string -> string -> unit = <fun>

Type:
   Grammar.Entry.print Pcaml.expr;;
to see the current entry of expressions.

The available levels are "top", "expr1", ":=", "||", "&&", "<", "^",
"+", "*", "**", "unary minus", "apply", "label", ".", "~-", "simple".
They are the one you can use as first parameter of add_infix:

  # add_infix "*" "op1";;

If you type
   Grammar.Entry.print Pcaml.expr;;
then you see that the rule with "op1" has been added in the level "*".

  # let op1 x y = x + y + 1;;
  Toplevel input:
  # let op1 x y = x + y + 1;;
	^^^
  Parse error: 'module' uppercase identifier expected after 'let' (in
    [str_item])

Normal, since "op1" is now a keyword. Mmmm... the normal form should be:
   let (op1) x y = x + y + 1;;
But it does not work... this is a bug in Camlp4 that I am going to fix.

A solution should be to define it before the "add_infix"...

But, in the meantime, this works:
   # let \op1 x y = x + y + 1;;
   val op1 : int -> int -> int = <fun>
   # 3 op1 4;;
   - : int = 8

-- 
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] infix precedence
  2002-05-28 22:44             ` Daniel de Rauglaudre
@ 2002-05-29  2:48               ` dengping zhu
  2002-05-29  8:42                 ` Daniel de Rauglaudre
  2002-06-21 17:54                 ` dengping zhu
  0 siblings, 2 replies; 12+ messages in thread
From: dengping zhu @ 2002-05-29  2:48 UTC (permalink / raw)
  To: Daniel de Rauglaudre; +Cc: Ocaml

Hi, Daniel, it works very well.
Thanks a lot!

Dengping




On Wed, 29 May 2002, Daniel de Rauglaudre wrote:

>Hi,
>
>On Tue, May 28, 2002 at 02:48:42PM -0400, dengping zhu wrote:
>> 
>> I tried camlp4 before. I got the example from the camlp4 tutorial and
>> modified a little bit. 
>
>Your code cannot work: you are defining a new entry, you are not using
>the entry of OCaml expressions, which is Pcaml.expr.
>
>  $ cat foo.ml
>  let add_infix lev op =
>  EXTEND
>    GLOBAL: Pcaml.expr;
>    Pcaml.expr: LEVEL $lev$
>      [ [ x = SELF; $op$; y = SELF -> <:expr< $lid:op$ $x$ $y$ >> ] ];
>  END;;
>  $ ocaml
>	  Objective Caml version 3.04+11 (2002-05-16)
>  
>  # #load "camlp4o.cma";;
>	  Camlp4s Parsing version 3.04+11
>  
>  # #load "pa_extend.cmo";;    
>  # #load "q_MLast.cmo";;  
>  # #use "foo.ml";;
>  val add_infix : string -> string -> unit = <fun>
>
>Type:
>   Grammar.Entry.print Pcaml.expr;;
>to see the current entry of expressions.
>
>The available levels are "top", "expr1", ":=", "||", "&&", "<", "^",
>"+", "*", "**", "unary minus", "apply", "label", ".", "~-", "simple".
>They are the one you can use as first parameter of add_infix:
>
>  # add_infix "*" "op1";;
>
>If you type
>   Grammar.Entry.print Pcaml.expr;;
>then you see that the rule with "op1" has been added in the level "*".
>
>  # let op1 x y = x + y + 1;;
>  Toplevel input:
>  # let op1 x y = x + y + 1;;
>	^^^
>  Parse error: 'module' uppercase identifier expected after 'let' (in
>    [str_item])
>
>Normal, since "op1" is now a keyword. Mmmm... the normal form should be:
>   let (op1) x y = x + y + 1;;
>But it does not work... this is a bug in Camlp4 that I am going to fix.
>
>A solution should be to define it before the "add_infix"...
>
>But, in the meantime, this works:
>   # let \op1 x y = x + y + 1;;
>   val op1 : int -> int -> int = <fun>
>   # 3 op1 4;;
>   - : int = 8
>
>-- 
>Daniel de RAUGLAUDRE
>daniel.de_rauglaudre@inria.fr
>http://cristal.inria.fr/~ddr/
>-------------------
>To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
>Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
>Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] infix precedence
  2002-05-29  2:48               ` dengping zhu
@ 2002-05-29  8:42                 ` Daniel de Rauglaudre
  2002-06-21 17:54                 ` dengping zhu
  1 sibling, 0 replies; 12+ messages in thread
From: Daniel de Rauglaudre @ 2002-05-29  8:42 UTC (permalink / raw)
  To: Ocaml

Hi,

On Tue, May 28, 2002 at 10:48:33PM -0400, dengping zhu wrote:

> Hi, Daniel, it works very well.
> Thanks a lot!

Thanks. BTW, another way to turn around the problem of "let (op1) x y"
which does not work (the problem is actually more complicated that I
thought), you can give the function another name, for example by
changing:
    [ [ x = SELF; $op$; y = SELF -> <:expr< $lid:op$ $x$ $y$ >> ] ];
into:
    [ [ x = SELF; $op$; y = SELF -> <:expr< $lid:"f_" ^ op$ $x$ $y$ >> ] ];

This way, when doing
    add_infix "*" "op1"

the rule creates the infix "op1" associated with the function "f_op1"
that you can define without parsing problem with:
    let f_op1 x y = ...

and "a op1 b" is therefore equivalent to "f_op1 a b".

-- 
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] infix precedence
  2002-05-29  2:48               ` dengping zhu
  2002-05-29  8:42                 ` Daniel de Rauglaudre
@ 2002-06-21 17:54                 ` dengping zhu
  1 sibling, 0 replies; 12+ messages in thread
From: dengping zhu @ 2002-06-21 17:54 UTC (permalink / raw)
  To: Daniel de Rauglaudre; +Cc: Ocaml

Hi, Daniel, I have to raise some questions about infix declaration in
camlp4 again.

Now I defined some infix as follows:
------------------------------------
let add_infix lev op = 
  EXTEND
      GLOBAL: Pcaml.expr;
          Pcaml.expr: LEVEL $lev$    
	      [ [ x = SELF; $op$; y = SELF -> <:expr< $lid:op$ $x$ $y$
	      >> ] ];   
	        END;; 

let _ = add_infix "*" ">>*"
let _ = add_infix "<" "wth"
let _ = add_infix "||" "|||"
------------------------------------

Then I have a following function:

  let f = number ||| literal '-' >>* number wth (fun x -> -x)

(where number and literal are some function I defined before.)

According to the infix definition above, this function should 
work as:

  let f = number ||| (literal '-' >>* number wth (fun x -> -x))

because the precedence of 'wth' is higher than that of '|||'.
But, it turns out to evaluate as:

  let f = (number ||| literal '-' >>* number) wth (fun x -> -x)

So, I have to add parenthesis so that it can work properly.
Can you help me to figure out this problem because I want to get rid of
the parenthesis so that my code is more readable? 

Thanks a lot!
Dengping


On Tue, 28 May 2002, dengping zhu wrote:

>Hi, Daniel, it works very well.
>Thanks a lot!
>
>Dengping
>
>
>
>
>On Wed, 29 May 2002, Daniel de Rauglaudre wrote:
>
>>Hi,
>>
>>On Tue, May 28, 2002 at 02:48:42PM -0400, dengping zhu wrote:
>>> 
>>> I tried camlp4 before. I got the example from the camlp4 tutorial and
>>> modified a little bit. 
>>
>>Your code cannot work: you are defining a new entry, you are not using
>>the entry of OCaml expressions, which is Pcaml.expr.
>>
>>  $ cat foo.ml
>>  let add_infix lev op =
>>  EXTEND
>>    GLOBAL: Pcaml.expr;
>>    Pcaml.expr: LEVEL $lev$
>>      [ [ x = SELF; $op$; y = SELF -> <:expr< $lid:op$ $x$ $y$ >> ] ];
>>  END;;
>>  $ ocaml
>>	  Objective Caml version 3.04+11 (2002-05-16)
>>  
>>  # #load "camlp4o.cma";;
>>	  Camlp4s Parsing version 3.04+11
>>  
>>  # #load "pa_extend.cmo";;    
>>  # #load "q_MLast.cmo";;  
>>  # #use "foo.ml";;
>>  val add_infix : string -> string -> unit = <fun>
>>
>>Type:
>>   Grammar.Entry.print Pcaml.expr;;
>>to see the current entry of expressions.
>>
>>The available levels are "top", "expr1", ":=", "||", "&&", "<", "^",
>>"+", "*", "**", "unary minus", "apply", "label", ".", "~-", "simple".
>>They are the one you can use as first parameter of add_infix:
>>
>>  # add_infix "*" "op1";;
>>
>>If you type
>>   Grammar.Entry.print Pcaml.expr;;
>>then you see that the rule with "op1" has been added in the level "*".
>>
>>  # let op1 x y = x + y + 1;;
>>  Toplevel input:
>>  # let op1 x y = x + y + 1;;
>>	^^^
>>  Parse error: 'module' uppercase identifier expected after 'let' (in
>>    [str_item])
>>
>>Normal, since "op1" is now a keyword. Mmmm... the normal form should be:
>>   let (op1) x y = x + y + 1;;
>>But it does not work... this is a bug in Camlp4 that I am going to fix.
>>
>>A solution should be to define it before the "add_infix"...
>>
>>But, in the meantime, this works:
>>   # let \op1 x y = x + y + 1;;
>>   val op1 : int -> int -> int = <fun>
>>   # 3 op1 4;;
>>   - : int = 8
>>
>>-- 
>>Daniel de RAUGLAUDRE
>>daniel.de_rauglaudre@inria.fr
>>http://cristal.inria.fr/~ddr/
>>-------------------
>>To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
>>Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
>>Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>>
>
>-------------------
>To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
>Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
>Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

end of thread, other threads:[~2002-06-21 17:54 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-28 15:42 [Caml-list] infix precedence dengping zhu
2002-05-28 15:54 ` Remi VANICAT
2002-05-28 16:00 ` John Prevost
2002-05-28 17:19   ` dengping zhu
2002-05-28 18:07     ` John Prevost
2002-05-28 18:16       ` dengping zhu
2002-05-28 18:32         ` Daniel de Rauglaudre
2002-05-28 18:48           ` dengping zhu
2002-05-28 22:44             ` Daniel de Rauglaudre
2002-05-29  2:48               ` dengping zhu
2002-05-29  8:42                 ` Daniel de Rauglaudre
2002-06-21 17:54                 ` dengping zhu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).