caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: oleg@okmij.org
To: caml-list@inria.fr
Cc: jun.furuse@gmail.com
Subject: Re: [Caml-list] [ANN] ppx_monadic.1.0.2, ppx for monadic do, pattern
Date: Wed, 14 Jan 2015 03:40:56 -0500 (EST)	[thread overview]
Message-ID: <20150114084056.140F6C38A1@www1.g3.pair.com> (raw)
In-Reply-To: <CAAoLEWswALkLSFj-_sMM8h3+2rNn2Y_8PH70BXugvgmUUceL1g@mail.gmail.com>


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.)


  reply	other threads:[~2015-01-14  8:40 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 ` oleg [this message]
2015-01-18 14:47   ` [Caml-list] [ANN] ppx_monadic.1.0.2, ppx for monadic do, pattern Jun Furuse
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=20150114084056.140F6C38A1@www1.g3.pair.com \
    --to=oleg@okmij.org \
    --cc=caml-list@inria.fr \
    --cc=jun.furuse@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).