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