Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Brian Rogoff <bpr@best.com>
To: Steve Stevenson <steve@cs.clemson.edu>
Cc: caml-list@inria.fr
Subject: Re: How do you declare infix in Ocaml
Date: Wed, 31 May 2000 09:45:39 -0700 (PDT)	[thread overview]
Message-ID: <Pine.BSF.4.21.0005310919430.26023-100000@shell5.ba.best.com> (raw)
In-Reply-To: <14643.48479.50162.753370@merlin.cs.clemson.edu>

If you take a look at, for instance, the Num library, or the types of 
the infixes in Pervasives, you'll notice that the infix is parenthesized. 
That is also how you declare new ones, or redefine the existing ones. 
For example, 

# let (+@) x y = x + y - 1;;
val ( +@ ) : int -> int -> int = <fun>
# 1 +@ 0;;
- : int = 0

and the new (+@) gets its precedence from the first character of the
lexeme, the "+".

Prefixes are defined similarly, 

# let (~@) = fun x -> String.uppercase x ;;
val ( ~@ ) : string -> string = <fun>
# ~@ "hi there";;
- : string = "HI THERE"

You can also redefine the existing infixes and prefixes, including the
ones like mod, not, and or, but that would be very nasty. 

I wish that there was some mechanism like in Haskell to make infixes out 
of identifiers, but of course we would be back to having directives again 
to resolve ambiguities in precedence and associativity if this were the
case. Camlp4 helps here.

-- Brian

On Tue, 30 May 2000, Steve Stevenson wrote:

> In caml there are directives to do this. The obvious doesn't work in
> Ocaml.
> 
> best regards
> 
> steve
> 
> 




      parent reply	other threads:[~2000-06-03  7:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-05-30 13:10 Steve Stevenson
2000-05-30 20:32 ` Pierre Weis
2000-05-31 16:45 ` Brian Rogoff [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=Pine.BSF.4.21.0005310919430.26023-100000@shell5.ba.best.com \
    --to=bpr@best.com \
    --cc=caml-list@inria.fr \
    --cc=steve@cs.clemson.edu \
    /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