Article View: fa.caml
Article #144Re: [Caml-list] using infix operators/functions in modules when not using "open"
From: Anthony Tavener
Date: Fri, 27 Apr 2012 00:28
Date: Fri, 27 Apr 2012 00:28
71 lines
5273 bytes
5273 bytes
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 <hywang@pobox.com> 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
>
>
--
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
Technical Details
Message-ID:
<fa.T9dOBLTpnsmqJl5q+8SSH9L+jBQ@ifi.uio.no>Path:
arc1-ca.pugleaf.net!r9ni102448pbh.0!nntp.google.com!news2.google.com!goblin3!goblin.stu.neva.ru!newsfeed3.funet.fi!newsfeeds.funet.fi!uio.no!nntp.uio.no!.POSTED!not-for-mailReferences:
<fa.ofhQjxcsFv94sv/nWA+yTdO/Akc@ifi.uio.no> <fa.M6cVL/vUGSfNoz3BI3kTRG8al/c@ifi.uio.no>Show Full Headers
Complete Article Headers
X-Google-Thread: ff861,b3875ae36b84daab
X-Google-NewGroupId: yes
X-Google-Attributes: gidc0fe4b917e,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Received: by 10.68.230.98 with SMTP id sx2mr3080834pbc.1.1335486537386;
Thu, 26 Apr 2012 17:28:57 -0700 (PDT)
Path: arc1-ca.pugleaf.net!r9ni102448pbh.0!nntp.google.com!news2.google.com!goblin3!goblin.stu.neva.ru!newsfeed3.funet.fi!newsfeeds.funet.fi!uio.no!nntp.uio.no!.POSTED!not-for-mail
From: Anthony Tavener <anthony.tavener@gmail.com>
Newsgroups: fa.caml
Subject: Re: [Caml-list] using infix operators/functions in modules when not
using "open"
Date: Fri, 27 Apr 2012 00:28:56 UTC
Organization: Internet mailing list
Lines: 79
Message-ID: <fa.T9dOBLTpnsmqJl5q+8SSH9L+jBQ@ifi.uio.no>
References: <fa.ofhQjxcsFv94sv/nWA+yTdO/Akc@ifi.uio.no> <fa.M6cVL/vUGSfNoz3BI3kTRG8al/c@ifi.uio.no>
NNTP-Posting-Host: mail-jess.uio.no
Mime-Version: 1.0
X-Trace: readme.uio.no 1335486536 4078 129.240.7.9 (27 Apr 2012 00:28:56 GMT)
X-Complaints-To: abuse@uio.no
NNTP-Posting-Date: Fri, 27 Apr 2012 00:28:56 +0000 (UTC)
Cc: caml-list@inria.fr
To: Haoyang Wang <hywang@pobox.com>
X-IronPort-AV: E=Sophos;i="4.75,487,1330902000";
d="scan'208";a="155831130"
X-Authentication-Warning: walapai.inria.fr: sympa set sender to caml-list-owner@inria.fr using -f
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"
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==
In-Reply-To: <3C0F509D-8590-4D45-A586-83630088C7B5@pobox.com>
X-Sequence: 3974
List-Id: <caml-list.inria.fr>
List-Archive: <https://sympa-roc.inria.fr/wws/arc/caml-list>
List-Help: <mailto:sympa@inria.fr?subject=help>
List-Owner: <mailto:caml-list-request@inria.fr>
List-Post: <mailto:caml-list@inria.fr>
List-Subscribe: <mailto:sympa@inria.fr?subject=subscribe%20caml-list>
List-Unsubscribe: <mailto:sympa@inria.fr?subject=unsubscribe%20caml-list>
X-FA-Processed: Removed HTML alternative
Original-Date: Thu, 26 Apr 2012 18:28:32 -0600
Original-Message-Id: <CAN=ouMRvAUhtEv5ofZOKgR6yuUqWAZd6z8+TM0aUHjX0m2hR_Q@mail.gmail.com>
Original-References: <CAN2fQM6PmfgkBspx1Js0yq8r2hbtd15mhvDXQ6tUcmAL46q=rw@mail.gmail.com>
<3C0F509D-8590-4D45-A586-83630088C7B5@pobox.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit