From: Jun Furuse <jun.furuse@gmail.com>
To: oleg@okmij.org, caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] [ANN] ppx_monadic.1.0.2, ppx for monadic do, pattern
Date: Sun, 18 Jan 2015 22:47:16 +0800 [thread overview]
Message-ID: <CAAoLEWvdRt=nVRKD7d2fVvxeLujurV4+jMaEkm6VWg+oQHrdoQ@mail.gmail.com> (raw)
In-Reply-To: <20150114084056.140F6C38A1@www1.g3.pair.com>
Thanks,
let! is not valid in the vanilla syntax therefore I guess you have
patched the compiler.
Current OCaml syntax has shortage of pattern binding expression and
only usable is let%xxx p = e in which is a bit pain for ppx writers.
The pattern part of p <-- e is actually an expression and you
cannot simply write real patterns like (x, y) as z. You still can
write it using an extension like [%p? (x,y) as z] but it is lousy...
Jun
On Wed, Jan 14, 2015 at 4:40 PM, <oleg@okmij.org> wrote:
>
> Jun Furuse wrote:
>> * Monadic do notation: do_;
>> * Pattern guards: when p <-- e -> ..
>
> This reminds me: MetaOCaml incorporates the let! notation suggested by
> Nicolas Pouillard and implemented by Alain Frisch. The following is
> the example of using the notation, excerpted from the file
> metalib/test/pythagorian_triples.ml
> in the BER MetaOCaml distribution/source.
>
> (* The example uses left recursion and truly infinite streams! *)
> (* Don't try this in Prolog or in Haskell's MonadPlus. *)
>
> let rec numb () = (* infinite stream of integers *)
> yield (mplus (let! n = numb in ret (n+1)) (* left recursion! *)
> (ret 0)) ()
> ;;
>
> let pyth : (int * int * int) NonDet.stream =
> let! i = numb in
> let! () = guard (i>0) in
> let! j = numb in
> let! () = guard (j>0) in
> let! k = numb in
> let! () = guard (k>0) in
> (* Just to illustrate the `let' form within let! *)
> let test x = x*x = j*j + k*k in
> let! () = guard (test i) in
> ret (i,j,k)
> ;;
>
> let [(5, 4, 3); (5, 3, 4); (10, 8, 6); (10, 6, 8); (13, 12, 5); (13, 5, 12);
> (15, 12, 9); (15, 9, 12); (17, 15, 8); (17, 8, 15)]
> =
> run 10 pyth;;
>
>
> (The file also implements the non-determinism monad that is
> illustrated in the example.)
>
next prev parent reply other threads:[~2015-01-18 14:47 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-13 14:23 [Caml-list] [ANN] ppx_monadic.1.0.2, ppx for monadic do, pattern guards and monadic comprehension Jun Furuse
2015-01-14 8:40 ` [Caml-list] [ANN] ppx_monadic.1.0.2, ppx for monadic do, pattern oleg
2015-01-18 14:47 ` Jun Furuse [this message]
2015-01-19 7:33 ` [Caml-list] [ANN] ppx_monadic.1.0.2, ppx for monadic do, oleg
2015-01-19 8:34 ` Alain Frisch
2015-01-19 9:06 ` Gabriel Scherer
2015-01-19 9:40 ` Alain Frisch
2015-01-19 16:10 ` Jeremy Yallop
2015-01-19 8:56 ` [Caml-list] [ANN] ppx_monadic.1.0.2, ppx for monadic do, pattern Alain Frisch
2015-01-19 21:52 ` Drup
2015-01-20 3:53 ` Jun Furuse
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAAoLEWvdRt=nVRKD7d2fVvxeLujurV4+jMaEkm6VWg+oQHrdoQ@mail.gmail.com' \
--to=jun.furuse@gmail.com \
--cc=caml-list@inria.fr \
--cc=oleg@okmij.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox