From mboxrd@z Thu Jan 1 00:00:00 1970 X-Sympa-To: caml-list@inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q3QMarAZ010974 for ; Fri, 27 Apr 2012 00:36:53 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmUEAJPMmU/YSz5mcGdsb2JhbABFqEOJJyoBDAgOBxQDJIIAIgKBAwEHXRIBBQFXh2sLmgOCXgqeXo4ZgyUEiGONGoERjU89hCs X-IronPort-AV: E=Sophos;i="4.75,487,1330902000"; d="scan'208";a="141776415" Received: from gourmet7.spamgourmet.com (HELO gourmet8.spamgourmet.com) ([216.75.62.102]) by mail4-smtp-sop.national.inria.fr with ESMTP; 27 Apr 2012 00:36:48 +0200 Received: from spamgourmet by gourmet7.spamgourmet.com with local (Exim 4.69) (envelope-from ) id 1SNXIs-0000IC-L4 for caml-list@inria.fr; Thu, 26 Apr 2012 22:36:46 +0000 Received: from mail-pb0-f48.google.com ([209.85.160.48]) by gourmet7.spamgourmet.com with esmtp (Exim 4.69) (envelope-from ) id 1SNXIs-0000I2-FG for ; Thu, 26 Apr 2012 22:36:46 +0000 Received: by pbbjt11 with SMTP id jt11so290859pbb.7 for <>; Thu, 26 Apr 2012 15:36:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-originating-ip:date:message-id:subject:from:to :content-type:x-gm-message-state; bh=16XVW7pC+Q9paJlI60TBCMvbtz01XmBmVfZCDT+J9A4=; b=HY0gRUd2gHQu88yTkpK66pXSLsCxYf4MXCXSP97GZpUkK6+/QjsAtsVnhijQWLkdfu OHb5Nif0vJ9coo9OYY7U0UNgViqvbsAZm4lnhcWi2GJzbKlbLdmGCadSfLiBXrLQs4fx gFGJdS5Jxt7qf8Iw832ZXUKyplWjkAUczBKa0O3FzvVDI9MN3MCaZgbCIzRKarF1yy06 hvQkLScSEx+MnAxBgSyZX1hkSEqwQFaHl4x0Erac4MWAPj6LrBMm4gjBec15FEgGWAqW 8zCeFhku4xMjRK/fAHMR5dm5IOC16NCvp9QzlMMF9mCpQA1N5lVyFILMqAidMhT1lcDN njQQ== MIME-Version: 1.0 Received: by 10.68.130.130 with SMTP id oe2mr18507393pbb.160.1335479806081; Thu, 26 Apr 2012 15:36:46 -0700 (PDT) Received: by 10.68.225.35 with HTTP; Thu, 26 Apr 2012 15:36:46 -0700 (PDT) X-Originating-IP: [173.167.122.54] Date: Thu, 26 Apr 2012 15:36:46 -0700 Message-ID: From: ocamllist.robertwork@spamgourmet.com To: caml-list@inria.fr Content-Type: multipart/alternative; boundary=047d7b15ad97723bf404be9c9ff0 X-Gm-Message-State: ALoCoQkqM9R8D4ViD1qPDEl1992A+z9unNuc7yY6vxBBJCeMtd9IHVU3/VS5Ajxm0Oy13dmSCDnT X-Spamgourmet: X-Validation-by: ocamllist.robertwork@spamgourmet.com Subject: [Caml-list] using infix operators/functions in modules when not using "open" --047d7b15ad97723bf404be9c9ff0 Content-Type: text/plain; charset=ISO-8859-1 I'm a OCaml newbie. I don't understand how to use infix functions that are in modules when I don't want to use "open". I did discover http://xahlee.org/ocaml/functions.html which explains that an infix operator can be used as a prefix. So, this format: ((Module.(op)) "foo" "bar") does seem to work. But, intuitively, it seems like: "foo" Module.(op) "bar" would work -- it doesn't. Is there a way to keep the infix notation? Thanks. --047d7b15ad97723bf404be9c9ff0 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I'm a OCaml newbie. =A0I don't understand how to use infix function= s that are in modules when I don't want to use "open".
I did discover=A0http://xahlee.org/ocaml/functions.html which explains that an inf= ix operator can be used as a prefix. =A0So, this format:

=A0 ((Module.(op)) "foo" "bar")

does seem to work. =A0But, intuitively, it seems like= :

=A0"foo" Module.(op) "bar"

would work -- it doesn't.

= Is there a way to keep the infix notation?

Thanks.=

--047d7b15ad97723bf404be9c9ff0-- From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q3QN1w0j012078 for ; Fri, 27 Apr 2012 01:01:58 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqkBAGfSmU/RVdIykGdsb2JhbABFgx2uTQgiAQEBAQkJDQcUBCOCCQEBAQMBEgIsATkDAQsBBQVGNAEFARwZIoddAwYFC5xuCo8WhUEnDYlNAQULjg6CQmMEiGONGoERhGOIbD2BWIJT X-IronPort-AV: E=Sophos;i="4.75,487,1330902000"; d="scan'208";a="141777610" Received: from mail-pz0-f50.google.com ([209.85.210.50]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 27 Apr 2012 01:01:52 +0200 Received: by dakh32 with SMTP id h32so158265dak.9 for ; Thu, 26 Apr 2012 16:01:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to:x-mailer; bh=CyPyqkCLSvqE3Iw1E/ljYrbNAboylQIyBeC3jQxrej4=; b=HzFwfXMVTID1dkNSAETod9b3sVsNA4J1krPz/g0zHnqeFym4OoKyEX6gr+iQNxhZUT /JVqwmj/lj/D2wwXLcN2MUcuZbY9vnpIKcbaIBRMeECdLdly4dA860vJxLlWJBxfO6LP qJ2NoBA6vnfaEqXSheMNZUMP0OazVpj4w12SRT4Wdonq01U6BTVZo5Vo9IxBn5FAnoxG ROxv773SYMadiwOCUfj5JP/9dmepfYDurYCne9fZYC0G8IhFBV5HrO9smEnL3ijKaDmM FQ9Of7hi9ZwaH9+UliDT4P57/HH+ryozBr8fjNer7uopGJ+57LU4rn4v1wM9VtM7bkbj pSjA== Received: by 10.68.223.227 with SMTP id qx3mr7799249pbc.1.1335481310723; Thu, 26 Apr 2012 16:01:50 -0700 (PDT) Received: from [192.168.1.106] (50-76-32-210-ip-static.hfc.comcastbusiness.net. [50.76.32.210]) by mx.google.com with ESMTPS id pn10sm2994487pbb.22.2012.04.26.16.01.48 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 26 Apr 2012 16:01:49 -0700 (PDT) Sender: Haoyang Wang Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 (Apple Message framework v1257) From: Haoyang Wang In-Reply-To: Date: Thu, 26 Apr 2012 16:01:46 -0700 Message-Id: <3C0F509D-8590-4D45-A586-83630088C7B5@pobox.com> References: To: caml-list@inria.fr X-Mailer: Apple Mail (2.1257) Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id q3QN1w0j012078 Subject: Re: [Caml-list] using infix operators/functions in modules when not using "open" On Apr 26, 2012, at 3:36 PM, ocamllist.robertwork@spamgourmet.com wrote: > I'm a OCaml newbie. I don't understand how to use infix functions that are in modules when I don't want to use "open". > > I did discover http://xahlee.org/ocaml/functions.html which explains that an infix operator can be used as a prefix. So, this format: > > ((Module.(op)) "foo" "bar") > > does seem to work. But, intuitively, it seems like: > > "foo" Module.(op) "bar" > > would work -- it doesn't. > > Is there a way to keep the infix notation? > > Thanks. Module.("foo" (op) "bar") From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q3R0Scpr013802 for ; Fri, 27 Apr 2012 02:28:38 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av0BADvnmU9KfVK2kGdsb2JhbABFn2yIWQGJJggiAQEBAQkJDQcUBCOCCQEBAQMBEgIsARsSCwEDAQsGBQsDCg0hIgERAQUBChIGExIQhW+BbQEDBgULnSIKjCOCc4UgChknAwpXiHYBBQuRMwSIY40agRGNTz2EKoE9 X-IronPort-AV: E=Sophos;i="4.75,487,1330902000"; d="scan'208";a="155831071" Received: from mail-we0-f182.google.com ([74.125.82.182]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 27 Apr 2012 02:28:32 +0200 Received: by weyt57 with SMTP id t57so169512wey.27 for ; Thu, 26 Apr 2012 17:28:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=r3Q997Mkfu5qlB7bi29hGV8V/hjH1/6AdZp3/8B9c4Q=; b=kn/eh+snOKOVVtNaVHiKNgBglPbZSMJ9cMuJt/dkO8atOgLEp2Zl98+Y2J3/Wmqtsc 5O5lRomxk7ob9Tbbr/JnvRQy4awbhsAsAlFTvvAGZyOYtsmElnMZhTobDG/mzju1+eb/ 2oXIrHRZ2u/vPlp1EdHvdAkbHBrU+ohelIYiA2jfb6TZWj+87kncMjvhMkadDfDZlDms nQrU5jyq6MW/2lGKlaF9u8hBrvtn+U1yG3MtIf+LR2tIyotwqheJnPZTc9IPSnWIQ5be QuzL+vucY1mVlKhkaGV2f8Vj0/8+W2koEAYt9YUskr35tP9QAT2h91l6kRgIEchcV3ga WRQA== MIME-Version: 1.0 Received: by 10.180.104.231 with SMTP id gh7mr756815wib.10.1335486512501; Thu, 26 Apr 2012 17:28:32 -0700 (PDT) Received: by 10.223.143.82 with HTTP; Thu, 26 Apr 2012 17:28:32 -0700 (PDT) In-Reply-To: <3C0F509D-8590-4D45-A586-83630088C7B5@pobox.com> References: <3C0F509D-8590-4D45-A586-83630088C7B5@pobox.com> Date: Thu, 26 Apr 2012 18:28:32 -0600 Message-ID: From: Anthony Tavener To: Haoyang Wang Cc: caml-list@inria.fr Content-Type: multipart/alternative; boundary=f46d044288bc2e127204be9e2f36 Subject: Re: [Caml-list] using infix operators/functions in modules when not using "open" --f46d044288bc2e127204be9e2f36 Content-Type: text/plain; charset=ISO-8859-1 Haoyang Wang provided the answer you're looking for, I think! In case you are writing your own modules with infix operators, I've found the following style to be useful: --- Inside Vector.ml --- (* definition of some basic functions here... *) (* now some infix defs using the basic functions, in "Ops" submodule *) module Ops = struct let ( +| ) u v = add u v let ( -| ) u v = sub u v let ( *| ) a v = scale a v end open Ops (* so that they are usable within Vector itself *) --- --- Some other module without opening all of Vector --- open Vector.Ops let answer = a +| b let same_answer = Vector.add a b --- In some cases I'll also expose types in a Type submodule. This is to minimize name-collision with record fields, but have direct access to the fields in situations which it's appropriate (by doing "open Vector.Type", for example). Hope that's of some use! -Tony On Thu, Apr 26, 2012 at 5:01 PM, Haoyang Wang wrote: > > On Apr 26, 2012, at 3:36 PM, ocamllist.robertwork@spamgourmet.com wrote: > > > I'm a OCaml newbie. I don't understand how to use infix functions that > are in modules when I don't want to use "open". > > > > I did discover http://xahlee.org/ocaml/functions.html which explains > that an infix operator can be used as a prefix. So, this format: > > > > ((Module.(op)) "foo" "bar") > > > > does seem to work. But, intuitively, it seems like: > > > > "foo" Module.(op) "bar" > > > > would work -- it doesn't. > > > > Is there a way to keep the infix notation? > > > > Thanks. > > > Module.("foo" (op) "bar") > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > > --f46d044288bc2e127204be9e2f36 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Haoyang Wang provided the answer you're look= ing for, I think!

In case you are writing your own modules with infix operators, = I've found the following style to be useful:

--- Inside = Vector.ml=A0---
= (* definition of some basic functions here... *)
(* now some infix defs using the basic functions, in "Ops" = submodule *)
module Ops =3D struct
=A0 let ( +| ) u v =3D add u v
=A0 le= t ( -| ) u v =3D sub u v
=A0 let ( *| ) a v= =3D scale a v
end
open Ops (* = so that they are usable within Vector itself *)
---
--- Some other module without opening all of Vector ---
open Vector.Ops

let answer =3D a +| b
le= t same_answer =3D Vector.add a b
---

In = some cases I'll also expose types in a Type submodule. This is to minim= ize name-collision with record fields, but have direct access to the fields= in situations which it's appropriate (by doing "open Vector.Type&= quot;, for example).

Hope that's of some use!

= =A0-Tony

On Thu, Apr 26, 2012 at 5:01 PM, Haoyang Wang <hywang@pobox.c= om> wrote:

On Apr 26, 2012, at 3:36 PM, ocamllist.robertwork@spamgourmet.com wrote:

> I'm a OCaml newbie. =A0I don't understand how to use infix fun= ctions that are in modules when I don't want to use "open". >
> I did discover http://xahlee.org/ocaml/functions.html which explains tha= t an infix operator can be used as a prefix. =A0So, this format:
>
> =A0 ((Module.(op)) "foo" "bar")
>
> does seem to work. =A0But, intuitively, it seems like:
>
> =A0"foo" Module.(op) "bar"
>
> would work -- it doesn't.
>
> Is there a way to keep the infix notation?
>
> Thanks.


Module.("foo" (op) "bar")

--
Caml-list mailing list. =A0Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


--f46d044288bc2e127204be9e2f36-- From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q3R6vtUX029471 for ; Fri, 27 Apr 2012 08:57:55 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av0BALFCmk/RVdK2kWdsb2JhbABFn22SAggiAQEBAQkJDQcSKYIJAQEBAwESAiwBGxILAQMBCwYFCwMKDSEiAREBBQEKEgYTEgkHh1wBAwYFC51ACowjgnOFGQoZJwMKV4h2AQULkTgElX2BEY1PPYQN X-IronPort-AV: E=Sophos;i="4.75,489,1330902000"; d="scan'208";a="141802413" Received: from mail-iy0-f182.google.com ([209.85.210.182]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 27 Apr 2012 08:57:50 +0200 Received: by iahk25 with SMTP id k25so1058944iah.27 for ; Thu, 26 Apr 2012 23:57:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=ZP3PH/xz2nZJi05O5ZR5DVqN4Voh5/HulDjtNWmvuSE=; b=z9sMEhv3FVYYjUVQ8fsQjs5NIpAFGOqQDTiJRP5UyBjuZG6DpbL/2XQYl2/CN+vrGC TwwaAJNeInPO4AZ9DPoYXWzrlRcjlWMN5Kbzh6vKDD8TYuHBPCCKLu1R9fPrPTuv6dUV 1EOAX6A5/7z9Nngb5sQOgaTwjfYYcG8KWNcZuCkuKAUtsNHHDXfEV8QYUym/w/OVCvW3 btdnIZaN5X+gpTMQKuBk3zsuqzeZShrRhiju5JZwtl5naerGiHtEm6ttt+caKpP8Scze cnyp2MF9s6I9Qqbd/IFO2wE+j7HyRyHMqByqugyiTw+GsL8kn0ba2CP8tyBmQN9fQdKg 1YaQ== Received: by 10.50.217.164 with SMTP id oz4mr796688igc.70.1335509868667; Thu, 26 Apr 2012 23:57:48 -0700 (PDT) MIME-Version: 1.0 Received: by 10.50.140.100 with HTTP; Thu, 26 Apr 2012 23:57:08 -0700 (PDT) In-Reply-To: <3C0F509D-8590-4D45-A586-83630088C7B5@pobox.com> References: <3C0F509D-8590-4D45-A586-83630088C7B5@pobox.com> From: Gabriel Scherer Date: Fri, 27 Apr 2012 08:57:08 +0200 Message-ID: To: Haoyang Wang Cc: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id q3R6vtUX029471 Subject: Re: [Caml-list] using infix operators/functions in modules when not using "open" > Module.("foo" (op) "bar") This is a local open (a more explicit notation is "let open Module in foo op bar"). I think this is a fine solution: I don't like open, but local mitigates its flaws. Another solution is to rebind your operator locally: let (op) = Module.blah in "foo" op "bar" (of course Module.blah doesn't need to be an infix itself) If you are going to use an infix operator in a wide scope, I think that such a rebinding solution is nice because it's more explicit, which is good when it helps users understand the code. On Fri, Apr 27, 2012 at 1:01 AM, Haoyang Wang wrote: > > On Apr 26, 2012, at 3:36 PM, ocamllist.robertwork@spamgourmet.com wrote: > >> I'm a OCaml newbie.  I don't understand how to use infix functions that are in modules when I don't want to use "open". >> >> I did discover http://xahlee.org/ocaml/functions.html which explains that an infix operator can be used as a prefix.  So, this format: >> >>   ((Module.(op)) "foo" "bar") >> >> does seem to work.  But, intuitively, it seems like: >> >>  "foo" Module.(op) "bar" >> >> would work -- it doesn't. >> >> Is there a way to keep the infix notation? >> >> Thanks. > > > Module.("foo" (op) "bar") > > -- > Caml-list mailing list.  Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q3R8UPgP031992 for ; Fri, 27 Apr 2012 10:30:25 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtUCAGdYmk/ZSMDqlGdsb2JhbABFsXsiAQEBAQkLCQkUAySCCQEBBAE6PxALISUPAQQNGyETG4djAQMGCbIwHysNiVOKB4c8BJtehVyHbQ X-IronPort-AV: E=Sophos;i="4.75,490,1330902000"; d="scan'208";a="155869893" Received: from fmmailgate03.web.de ([217.72.192.234]) by mail1-smtp-roc.national.inria.fr with ESMTP; 27 Apr 2012 10:30:20 +0200 Received: from moweb001.kundenserver.de (moweb001.kundenserver.de [172.19.20.114]) by fmmailgate03.web.de (Postfix) with ESMTP id F2A471B3FF60C for ; Fri, 27 Apr 2012 10:30:19 +0200 (CEST) Received: from frosties.localnet ([95.208.118.96]) by smtp.web.de (mrweb002) with ESMTPA (Nemesis) id 0M9GYQ-1SUrqO3JfC-00ChwM; Fri, 27 Apr 2012 10:30:19 +0200 Received: from mrvn by frosties.localnet with local (Exim 4.77) (envelope-from ) id 1SNgZG-0003Re-Aa; Fri, 27 Apr 2012 10:30:18 +0200 From: Goswin von Brederlow To: Gabriel Scherer Cc: Haoyang Wang , caml-list@inria.fr References: <3C0F509D-8590-4D45-A586-83630088C7B5@pobox.com> Date: Fri, 27 Apr 2012 10:30:18 +0200 In-Reply-To: (Gabriel Scherer's message of "Fri, 27 Apr 2012 08:57:08 +0200") Message-ID: <87lilha86d.fsf@frosties.localnet> User-Agent: Gnus/5.110009 (No Gnus v0.9) XEmacs/21.4.22 (linux, no MULE) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Provags-ID: V02:K0:dolJV28pC9wzXrBP1c9Klh075xtxaQJTnef+LtSS4EQ qnNEzqzLDGiqPsilHhC2PiMVUUuymVP0SZrDup4fUBFhBRUOCf /KIebDxR+HCMLs39tW49lZYkE524abeZJHLvCsrDRJVqCtKIHH o6wax+wRRG0g8JyVjDFfWMjPNFGyT3L2tjnyOIiRVBTEL+O1ff 6QRZ72xhw2ioQgyoW4fUA== Subject: Re: [Caml-list] using infix operators/functions in modules when not using "open" Gabriel Scherer writes: >> Module.("foo" (op) "bar") > > This is a local open (a more explicit notation is "let open Module in > foo op bar"). I think this is a fine solution: I don't like open, but > local mitigates its flaws. > > Another solution is to rebind your operator locally: > > let (op) = Module.blah in > "foo" op "bar" > > (of course Module.blah doesn't need to be an infix itself) > > If you are going to use an infix operator in a wide scope, I think > that such a rebinding solution is nice because it's more explicit, > which is good when it helps users understand the code. And that also works more globally as in let (op) = Module.blah let foo x y = x (op) y MfG Goswin