Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] help me with infix in ocaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: dengping zhu <zhudp@c...>
Subject: [Caml-list] help me with infix in ocaml
Hi, all, please help me if you can!

Now I am converting a bunch of code from sml to ocaml. I met a problem
with infix in ocaml.

According to the example from camlp4, I got the following code:

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 the code in ocaml by 
# #use "foo.ml";;

I can add an infix, for example 
# add_infix "1" "op1";;

But till now, how can I use this infix "op1"? 
Actually, I have the following code in sml, I can not figure out how to
write it in ocaml.

        ...
        infix 2 --
	...
	fun (p -- q) (pos, ts) =
	    let
		val (x, posx, pos, ts) = p (pos, ts)
		val (y, posy, pos, ts) = q x (pos, ts)
	    in
		(y, Pos.union (posx, posy), pos, ts)
	    end

Thanks a lot!
Dengping
-------------------
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