English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2002-05-25 (15:17)
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";;

      [ "1" LEFTA [] | "2" LEFTA []];

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


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) =
		val (x, posx, pos, ts) = p (pos, ts)
		val (y, posy, pos, ts) = q x (pos, ts)
		(y, Pos.union (posx, posy), pos, ts)

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