caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Prefix operators in ocaml
@ 1999-01-21 14:42 Eduardo Gimenez
  1999-01-21 15:47 ` William Chesters
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Eduardo Gimenez @ 1999-01-21 14:42 UTC (permalink / raw)
  To: caml-list; +Cc: Eduardo.Gimenez


Hello,

Which is the "prefix" name in Ocaml for the multiplication on
integers? The symbols (+), (/), etc. work fine for the other
arithmetic operations, but the symbol (*) does not.

Similarly, is there any prefix name for the list constructor (a::l) ?
I am thinking in something like (::) .... 

Of course, I could define a function with the same behavior:
# let cons x y = x::y;;
val cons : 'a -> 'a list -> 'a list = <fun>

but this does not enable to write down expressions like 
match x with cons (a,l) -> l.

PS: I am working in the context of automatic generation of ocaml code,
and being able to have a uniform treatment for datatype constructors
would simplify things a lot....

Thanks in advance,
Eduardo Gimenez.




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

* Prefix operators in ocaml
  1999-01-21 14:42 Prefix operators in ocaml Eduardo Gimenez
@ 1999-01-21 15:47 ` William Chesters
  1999-01-21 16:04 ` Chris Keane
  1999-01-21 16:13 ` Jun P. Furuse
  2 siblings, 0 replies; 4+ messages in thread
From: William Chesters @ 1999-01-21 15:47 UTC (permalink / raw)
  To: caml-list

Eduardo Gimenez writes:
 > 
 > Hello,
 > 
 > Which is the "prefix" name in Ocaml for the multiplication on
 > integers? The symbols (+), (/), etc. work fine for the other
 > arithmetic operations, but the symbol (*) does not.

LOL :) :).

It's because (* begins a comment *).
You have to write ( * ).

This is truly disgusting and is on a par with C++'s "idiom"

	List<Array<int> >

 > Similarly, is there any prefix name for the list constructor (a::l) ?
 > I am thinking in something like (::) .... 

Yes, this is an example where following SML/NJ's habit of treating
constructors more uniformly with functions would be advantageous.
Although for all I know there may be implementation reasons not to do
it.




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

* Re: Prefix operators in ocaml
  1999-01-21 14:42 Prefix operators in ocaml Eduardo Gimenez
  1999-01-21 15:47 ` William Chesters
@ 1999-01-21 16:04 ` Chris Keane
  1999-01-21 16:13 ` Jun P. Furuse
  2 siblings, 0 replies; 4+ messages in thread
From: Chris Keane @ 1999-01-21 16:04 UTC (permalink / raw)
  To: Eduardo Gimenez; +Cc: caml-list

>>>>> On Thu, 21 Jan 1999, "EG" = Eduardo Gimenez wrote:

  EG> Which is the "prefix" name in Ocaml for the multiplication on
  EG> integers? The symbols (+), (/), etc. work fine for the other
  EG> arithmetic operations, but the symbol (*) does not.

I think you're probably just finding that the (* is being treated as the
start of a comment.  Put a space after the first bracket, thus: ( *), and
it should work as you require.

Chris.

------------------------------------------------------------------- ><> ---
    Hardware Compilation Group, Oxford University Computing Laboratory,
            Wolfson Building, Parks Road, Oxford, OX1 3QD, U.K.
    tel:  +44 (1865) (2)73865      e-mail:  Chris.Keane@comlab.ox.ac.uk
            http://www.comlab.ox.ac.uk/oucl/users/chris.keane/




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

* (no subject)
  1999-01-21 14:42 Prefix operators in ocaml Eduardo Gimenez
  1999-01-21 15:47 ` William Chesters
  1999-01-21 16:04 ` Chris Keane
@ 1999-01-21 16:13 ` Jun P. Furuse
  2 siblings, 0 replies; 4+ messages in thread
From: Jun P. Furuse @ 1999-01-21 16:13 UTC (permalink / raw)
  To: caml-list; +Cc: Eduardo Gimenez

> Which is the "prefix" name in Ocaml for the multiplication on
> integers? The symbols (+), (/), etc. work fine for the other
> arithmetic operations, but the symbol (*) does not.

You need a small trick. Try ( * ) or ( *).
 
> Similarly, is there any prefix name for the list constructor (a::l) ?
> I am thinking in something like (::) .... 

:: is not an infix operator, but an infix constructor. It is handled
specially by the parser. Like the other normal constructors, you
always need its arguments i.e.:

# type 'a option =
    None
  | Some of 'a

# Some;;
The constructor Some expects 1 argument(s),
but is here applied to 0 argument(s)

# fun x -> Some x;;
- : 'a -> 'a option = <fun>

The constructor names themselves are not functions in O'Caml.
 
-----------------------------------------------------------------------
Jun P. Furuse 					 Jun.Furuse@inria.fr
  INRIA
    Institut National de Recherche en Informatique et en Automatique




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

end of thread, other threads:[~1999-01-21 18:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-01-21 14:42 Prefix operators in ocaml Eduardo Gimenez
1999-01-21 15:47 ` William Chesters
1999-01-21 16:04 ` Chris Keane
1999-01-21 16:13 ` Jun P. Furuse

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