caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Haoyang Wang <hywang@pobox.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] using infix operators/functions in modules when not using "open"
Date: Fri, 27 Apr 2012 08:57:08 +0200	[thread overview]
Message-ID: <CAPFanBEofozEj3dRVU_c9_J2LUSp1DH7X8R=02GBd8BriFoLFA@mail.gmail.com> (raw)
In-Reply-To: <3C0F509D-8590-4D45-A586-83630088C7B5@pobox.com>

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


  parent reply	other threads:[~2012-04-27  6:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-26 22:36 ocamllist.robertwork
2012-04-26 23:01 ` Haoyang Wang
2012-04-27  0:28   ` Anthony Tavener
2012-04-27  6:57   ` Gabriel Scherer [this message]
2012-04-27  8:30     ` Goswin von Brederlow

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='CAPFanBEofozEj3dRVU_c9_J2LUSp1DH7X8R=02GBd8BriFoLFA@mail.gmail.com' \
    --to=gabriel.scherer@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=hywang@pobox.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).