caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Xavier Leroy <xleroy@pomerol>
To: jcmoreno@dia.ucm.es (Juan C. Gonzalez Moreno)
Cc: caml-list@margaux
Subject: Re: What about infix operator?
Date: Wed, 28 Oct 92 11:18:50 MET	[thread overview]
Message-ID: <9210281018.AA081826987@pomerol.inria.fr> (raw)
In-Reply-To: <36*jcmoreno@dia.ucm.es>; from "Juan C. Gonzalez Moreno" at Oct 27, 92 11:51 am

Caml Light allows you to define infix operators (that is,
functions), but not infix constructors. Constructors are not
functions. Concerning the :: infix constructor is built-in at the
level of the parser. What you propose is the best way to circumvent
this limitation:

        type rational = Frac of int * int;;
        let frac x y = Frac(x,y);;
        #infix "frac";;
        1 frac 2;;

However, you won't be able to use "frac" in left-hand sides of
pattern-matching.

As you have noticed, you are allowed to do:

        let Frac x y = Frac(x,y);;

though this changes the status of "Frac" from constructor to function.
Actually, this is a bug in the current implementation. The phrase
above should be rejected, just as the semantically equivalent fomr
below is rejected:

        let Frac = fun x y -> Frac(x,y);;

This might be fixed some day. So, don't rely on this behavior and name
differently the constructor "Frac" and the infix operator "frac".

> There is any possibility to define as
> prefix operators any combination of symbols, not only identifiers?.

Presently, no. Operators are restricted to be identifiers. Allowing more
operators (e.g. ++ or */ ) would be nice, but requires some changes in
the lexical conventions of Caml Light. For instance: 1+-2 without
blanks is currently parsed as 1 + (-2), but would probably have to be
parsed as prefix +- 1 2 with this extension.

Regards,

- Xavier Leroy




           reply	other threads:[~1992-10-28 11:27 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <36*jcmoreno@dia.ucm.es>]

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=9210281018.AA081826987@pomerol.inria.fr \
    --to=xleroy@pomerol \
    --cc=caml-list@margaux \
    --cc=jcmoreno@dia.ucm.es \
    /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).