caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Vincenzo Ciancia <vincenzo_yahoo_addressguard-gmane@yahoo.it>
To: caml-list@inria.fr
Subject: Re: infix functions
Date: Fri, 27 May 2005 13:13:07 +0200	[thread overview]
Message-ID: <d76v7k$3c3$1@sea.gmane.org> (raw)
In-Reply-To: <ad8cfe7e050527030652565b3@mail.gmail.com>

Jonathan Roewen wrote:

> Hi,
> 
> I see some pervasive functions are infix, and I'm wondering if there's
> any plan to support making any arbitrary infix functions?
> 
> For instance, the Int32 (etc) modules are horrible to use cause of the
> prefix functions. These are perfect candidates for being infix.

Not arbitrary, but there are some "free" symbols that can be defined (I
don't know exactly how many and what, but I guess it's on the manual or in
the lexer :) ), and all the infix operators can be redefined. Example of
redefining "+":

########
# module InfixInt32 = struct
    let (+) = Int32.add
  end;;
module InfixInt32 : sig val ( + ) : int32 -> int32 -> int32 end
# 3+3;;
- : int = 6
# open InfixInt32;;
# 3+3;;
This expression has type int but is here used with type int32
#######

example of defining "+*"

#######
# let (+*) = Int32.add;;
val ( +* ) : int32 -> int32 -> int32 = <fun>
# 30l +* 20l;;
- : int32 = 50l
#######

I don't know if there is a way to force inlining of "+*" though, but I
suppose that you could finally resort to defining your operators in camlp4

http://pauillac.inria.fr/caml/camlp4/manual/manual006.html

see section 5.3.1

Bye

Vincenzo

-- 
Please note that I do not read the e-mail address used in the from field but
I read vincenzo_ml at yahoo dot it
Attenzione: non leggo l'indirizzo di posta usato nel campo from, ma leggo
vincenzo_ml at yahoo dot it



      parent reply	other threads:[~2005-05-27 11:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-27 10:06 [Caml-list] " Jonathan Roewen
2005-05-27 10:58 ` Richard Jones
2005-05-27 12:46   ` padiolea
2005-05-27 14:20     ` William D. Neumann
2005-05-27 11:12 ` Jean-Christophe Filliatre
2005-05-27 11:13 ` Vincenzo Ciancia [this message]

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='d76v7k$3c3$1@sea.gmane.org' \
    --to=vincenzo_yahoo_addressguard-gmane@yahoo.it \
    --cc=caml-list@inria.fr \
    /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).