caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Michael Alexander Hamburg <hamburg@fas.harvard.edu>
To: caml-list@pauillac.inria.fr
Subject: Re: [Caml-list] Q: Correct locations for macro camlp4 extensions
Date: Mon, 23 Aug 2004 19:16:09 -0400 (EDT)	[thread overview]
Message-ID: <Pine.LNX.4.58.0408231842040.6046@ls02.fas.harvard.edu> (raw)
In-Reply-To: <20040823182936.GA8152@annexia.org>

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

instead of

# sort (fun a b -> compare (fst a) (fst b)) l;;

I know that the last form is probaly faster at runtime than the first
ones, but my programs don't have to run fast.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  parent reply	other threads:[~2004-08-23 23:16 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-23  9:33 Jan Kybic
2004-08-23 10:59 ` skaller
2004-09-03 14:37   ` Yamagata Yoriyuki
2004-09-04  2:12     ` skaller
2004-08-23 17:21 ` Michael Alexander Hamburg
2004-08-23 18:29   ` Richard Jones
2004-08-23 20:33     ` David Brown
2004-08-23 21:53       ` skaller
2004-08-23 23:16     ` Michael Alexander Hamburg [this message]
2004-08-24  7:43       ` Marcin 'Qrczak' Kowalczyk
2004-08-24  7:02   ` [Caml-list] " Jan Kybic
2004-08-24 16:31     ` Michael Alexander Hamburg

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.LNX.4.58.0408231842040.6046@ls02.fas.harvard.edu \
    --to=hamburg@fas.harvard.edu \
    --cc=caml-list@pauillac.inria.fr \
    /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).