Browse thread
[Camlp4][trivial ?] Anonymous bind (for monads)
- Gabriel Kerneis
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Gabriel Kerneis <gabriel.kerneis@e...> |
| Subject: | [Camlp4][trivial ?] Anonymous bind (for monads) |
Hello,
I've got a little problem with camlp4. The following works perfectly
well :
#####################################################################
~/ocaml/camlp4% cat pa_bind.ml
module Id = struct
let name = "pa_bind"
let version = "$Id:$"
end
module Example (Syntax : Camlp4.Sig.Camlp4Syntax) = struct
include Syntax
EXTEND Gram
expr: LEVEL "top"
[[ t=expr; "foo"; f=expr ->
<:expr<
Lwt.bind $t$ (fun () -> $f$)
>>]];
END
end
module M = Camlp4.Register.OCamlSyntaxExtension(Id)(Example)
~/ocaml/camlp4% ocamlc -c -pp camlp4of -I +camlp4 pa_bind.ml
~/ocaml/camlp4% cat test_bind.ml
let r = (Lwt_unix.sleep 5) foo (print_endline "42")
~/ocaml/camlp4% camlp4of -parser pa_bind.cmo test_bind.ml
let r = Lwt.bind (Lwt_unix.sleep 5) (fun () -> print_endline "42")
#####################################################################
But if I change "foo" to ">>" (which is the usual way to write an
anonymous bind for monads), it doesn't work anymore. I first thought the
reason was that ">>" is also the symbol for closing a quotation, but
trying "++" instead proved useless as well.
I'm certainly not a camlp4 guru so... what am I missing?
Thanks a lot.
Regards,
--
Gabriel