This site is updated infrequently. For up-to-date information, please visit the new OCaml website at ocaml.org.

[Caml-list] Q: Correct locations for macro camlp4 extensions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
 Date: 2004-08-23 (23:16) From: Michael Alexander Hamburg Subject: Re: [Caml-list] Q: Correct locations for macro camlp4 extensions
```On Mon, 23 Aug 2004, Richard Jones wrote:

> On Mon, Aug 23, 2004 at 01:21:25PM -0400, Michael Alexander Hamburg wrote:
> > [...] Or does it enable
> > expressions like (/ 5) or (+ 3) as in Haskell (that would be cool...)?
>
> You mean like:
>
> # let f = ((/) 5);;
> val f : int -> int = <fun>
> # f 1;;
> - : int = 5
>
> and similarly ((+) 3)?  Or do these expressions do something more
> profound that I can't now recall? -- It's been a good 10 years since I
> did any serious Haskell.

Actually, this sort of proves my point.  (/ 5) divides its argument by 5
in Haskell, which is what I at least would expect such an expression to
do. On the other hand, ((/) 5) divides 5 by its argument, because the
first argument to an operator goes on the left, not the right.  To write
the equivalent of (/ 5), you have to write (fun x -> x/5).  More important
than tripling the number of characters is that non-commutative operators
make the ((op) foo) notation confusing.

If I ever come to understand camlp4, and a module to enable this syntax
isn't there, I'll try to add it, because I find it handy in Haskell.
Another syntax construction that I might write up (which I'm not aware of
in any programming language) would be something like

(f _ x _ _ y) translates into (fun p1 p2 p3 -> f p1 x p2 p3 y)

I don't think that the use of _ can be ambiguous in an expression like
this... any counterexamples?

>From my knowledge of Camlp4, this seems like it would be a lot more
difficult than the Haskell operator currying.

> Rich.
>
> --
> Richard Jones. http://www.annexia.org/ http://www.j-london.com/
> Merjis Ltd. http://www.merjis.com/ - improving website return on investment
> http://www.winwinsales.co.uk/ - CRM improvement consultancy

Regards,

Mike

P.S.
Lest you think I've gone compactness-crazy, I've been doing a fair amount
of symbolic and functional manipulation in O'Caml, and compressed notation
for functions helps me a lot.  When I have n lists of pairs to sort by the
first element of the tuple, or some other function like that, it saves me
a significant amount of programming effort to write

# let (<-<<) f g a b = f (g a) (g b);;
or
# let sort_by g a b = sort (compare (g a) (g b));;

so that I can write

# sort (compare <-<< fst) l;;
or
# sort_by fst l