From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id AD5047FBCE for ; Wed, 14 Jan 2015 09:40:59 +0100 (CET) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of oleg@okmij.org) identity=pra; client-ip=66.39.3.115; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="oleg@okmij.org"; x-sender="oleg@okmij.org"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of oleg@okmij.org designates 66.39.3.115 as permitted sender) identity=mailfrom; client-ip=66.39.3.115; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="oleg@okmij.org"; x-sender="oleg@okmij.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@www1.g3.pair.com) identity=helo; client-ip=66.39.3.115; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="oleg@okmij.org"; x-sender="postmaster@www1.g3.pair.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkgBADgrtlRCJwNzd2dsb2JhbABbg1hYgjbDTIV1AoEUQwEBAQEBEQEMBw8HQoQNAQUnUhsYCRMhHSuIRc9mAQEBAQYBAQEBAR2PeQcWgwCBEwWJZoghhUcBiX+HfYQuIDGCQwEBAQ X-IPAS-Result: AkgBADgrtlRCJwNzd2dsb2JhbABbg1hYgjbDTIV1AoEUQwEBAQEBEQEMBw8HQoQNAQUnUhsYCRMhHSuIRc9mAQEBAQYBAQEBAR2PeQcWgwCBEwWJZoghhUcBiX+HfYQuIDGCQwEBAQ X-IronPort-AV: E=Sophos;i="5.07,754,1413237600"; d="scan'208";a="96351140" Received: from www1.g3.pair.com ([66.39.3.115]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 14 Jan 2015 09:40:58 +0100 Received: by www1.g3.pair.com (Postfix, from userid 9370) id 140F6C38A1; Wed, 14 Jan 2015 03:40:56 -0500 (EST) From: oleg@okmij.org cc: jun.furuse@gmail.com To: caml-list@inria.fr In-reply-to: Message-Id: <20150114084056.140F6C38A1@www1.g3.pair.com> Date: Wed, 14 Jan 2015 03:40:56 -0500 (EST) Subject: Re: [Caml-list] [ANN] ppx_monadic.1.0.2, ppx for monadic do, pattern 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.)