caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* How do you declare infix in Ocaml
@ 2000-05-30 13:10 Steve Stevenson
  2000-05-30 20:32 ` Pierre Weis
  2000-05-31 16:45 ` Brian Rogoff
  0 siblings, 2 replies; 3+ messages in thread
From: Steve Stevenson @ 2000-05-30 13:10 UTC (permalink / raw)
  To: caml-list

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

best regards

steve




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How do you declare infix in Ocaml
  2000-05-30 13:10 How do you declare infix in Ocaml Steve Stevenson
@ 2000-05-30 20:32 ` Pierre Weis
  2000-05-31 16:45 ` Brian Rogoff
  1 sibling, 0 replies; 3+ messages in thread
From: Pierre Weis @ 2000-05-30 20:32 UTC (permalink / raw)
  To: Steve Stevenson; +Cc: caml-list

Infixes in Ocaml are ordinary lexems: any sequence of symbols is an
infix that has the precedence of its first character.

For instance += is an infix that has the same precedence as +.

There are no other user's infixes in O'Caml.

Best regards,

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://cristal.inria.fr/~weis/





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How do you declare infix in Ocaml
  2000-05-30 13:10 How do you declare infix in Ocaml Steve Stevenson
  2000-05-30 20:32 ` Pierre Weis
@ 2000-05-31 16:45 ` Brian Rogoff
  1 sibling, 0 replies; 3+ messages in thread
From: Brian Rogoff @ 2000-05-31 16:45 UTC (permalink / raw)
  To: Steve Stevenson; +Cc: caml-list

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




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2000-06-03  7:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-30 13:10 How do you declare infix in Ocaml Steve Stevenson
2000-05-30 20:32 ` Pierre Weis
2000-05-31 16:45 ` Brian Rogoff

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