caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Pierre Weis <pierre.weis@inria.fr>
To: Jon Harrop <postmaster@jdh30.plus.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] kprintf with user formatters
Date: Thu, 22 Jul 2004 17:39:01 +0200	[thread overview]
Message-ID: <20040722173901.A18239@pauillac.inria.fr> (raw)
In-Reply-To: <200407212141.45191.postmaster@jdh30.plus.com>; from postmaster@jdh30.plus.com on Wed, Jul 21, 2004 at 09:41:45PM +0100

[...]
> Is "match pred with true -> expr1 | false -> expr2" not
> equivalent to "if pred then expr1 else expr2"? If so, isn't pattern
> matching a fourth lazy construct?

Yes indeed, if you consider ``match'' as an operator, which is a bit
hairy, since match would be a (2n+1)-ary operator (for any given
positive integer n), taking as input 1 expression (the one to be
matched) and n (pattern, expression) pairs to match the
expression. Given that there is no notion of evaluation semantics
associated to a pattern (in the sense of the evaluation of expression)
this would be strange. However, the very match expression you
mentioned has indeed something of a lazyness behavior, since it is
indeed equivalent of an ``if ... then ... else ...'' construct, as
I know you know :)

> Just after I wrote that last post I realised that this approach
> could actually be useful in numerical contexts. As a trivial
> example, integer multiply could lazily evaluate its second argument
> (only when it is pure, if conventional semantics are to be
> preserved), not needing it if the first argument is zero.

I don't think the gain would overcome the cost of having to create
thunks in practice. On the other hand, taht would lead to evaluate the
operation 0 * expr to 0, even if the computation of expr would lead to
divergence (never terminates or fails). It's mathematically kind of
weird, I think. For instance, you would have a hard time to persuade a
matematician that

0 * ln (0)

is well-defined and evaluates to 0, ``because ln (0) has not to be
considered at all given the left operand''.

Hence, as far as I know, arithmetics operators are always considered
strict in lazy languages.

> This may be useful in more complicated settings, i.e. when dealing
> with data structures rather than primitive types and when predicates
> over the data structure can be evaluated much more quickly than the
> corresponding expression.

I'm a bit lost here. Could you explain a bit ?

> Such functionality can, of course, be implemented in vanilla
> OCaml. But I'd like to see a language which allowed mathematics to
> be expressed in a notation as close to conventional written form as
> possible (although I prefer type distinctions, like "+" vs "+.")
> whilst retaining efficiency (I'd also like to see deforesting,
> e.g. in vector expressions without having to resort to maps, folds
> etc.).

Yes, we all want such a language. Caml is the best approximation I
know, wrt a perfect match between efficiency and notational facility.

> Perhaps an OCaml -> OCaml optimising compiler would be a good
> project for someone? That way implementation details and their
> benefits can be examined without having to touch the OCaml
> compilers. I think it could be quite fun to play with such a
> thing...
>
> Cheers,
> Jon.

Yes, many people have dreamed upon (or even have planned to do) such a
tool in the past. These days, the availability of the camlp4 tools
would help a lot to perform such a goal...

Best regards,

Pierre Weis

INRIA, Projet Cristal, http://pauillac.inria.fr/~weis

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


  reply	other threads:[~2004-07-22 15:39 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-30 16:32 Damien
2004-07-14 21:10 ` Pierre Weis
2004-07-15  0:17   ` Markus Mottl
2004-07-15  7:30     ` David MENTRE
2004-07-15  7:59       ` Jean-Christophe Filliatre
2004-07-15 23:35         ` henri dubois-ferriere
2004-07-15  7:39     ` Damien
2004-07-15 12:19       ` Markus Mottl
2004-07-15 12:42         ` Basile Starynkevitch [local]
2004-07-15 13:45           ` Markus Mottl
2004-07-15 14:22             ` Basile Starynkevitch [local]
2004-07-15 14:57               ` Markus Mottl
2004-07-16  6:47               ` Pierre Weis
2004-07-16  7:13                 ` Jean-Christophe Filliatre
2004-07-16  7:23                   ` henri dubois-ferriere
2004-07-16  7:44                     ` Jean-Christophe Filliatre
2004-07-16 17:56                   ` Markus Mottl
2004-07-19  9:17                   ` Pierre Weis
2004-07-19  9:32                     ` Jean-Christophe Filliatre
2004-07-16  7:21                 ` henri dubois-ferriere
2004-07-16 17:44                 ` Markus Mottl
2004-07-19 10:10                   ` Pierre Weis
2004-07-19 10:43                     ` Jon Harrop
2004-07-21 15:52                       ` Pierre Weis
2004-07-21 17:43                         ` lazyness in ocaml (was : [Caml-list] kprintf with user formatters) Daniel Bünzli
2004-07-22 16:28                           ` Pierre Weis
2004-07-22 17:03                             ` William Lovas
2004-07-22 23:00                             ` skaller
2004-07-23  3:32                               ` William Lovas
2004-07-28  7:26                               ` Pierre Weis
2004-07-28  8:06                                 ` skaller
2004-07-28  8:29                                   ` Daniel Bünzli
2004-07-28  9:13                                   ` Pierre Weis
2004-07-28  9:36                                     ` skaller
2004-07-28  9:38                                     ` skaller
2004-07-28 10:17                                 ` Jason Smith
2004-07-28 12:31                                   ` skaller
2004-07-21 20:41                         ` [Caml-list] kprintf with user formatters Jon Harrop
2004-07-22 15:39                           ` Pierre Weis [this message]
2004-07-22 22:16                             ` [Caml-list] lazy evaluation: [Was: kprintf with user formatters] skaller
2004-07-22 22:42                             ` [Caml-list] kprintf with user formatters skaller
2004-07-22  8:05                         ` [Caml-list] wait instruction lehalle@miriad
2004-07-22  8:40                           ` Olivier Andrieu
2004-07-22 10:35                             ` lehalle@miriad
2004-07-22 10:33                           ` Vitaly Lugovsky
2004-07-16  6:17             ` [Caml-list] kprintf with user formatters Pierre Weis
2004-07-16 17:14               ` Markus Mottl
2004-07-19 10:00                 ` Pierre Weis
2004-07-16  6:02       ` Pierre Weis
2004-07-16  8:42         ` Damien
2004-07-19  9:00           ` Pierre Weis
2004-07-16 16:52         ` Markus Mottl
2004-07-19  9:28           ` Pierre Weis
2004-07-15 22:20     ` Pierre Weis
2004-07-15 23:01       ` Markus Mottl
2004-07-16 16:17     ` james woodyatt

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=20040722173901.A18239@pauillac.inria.fr \
    --to=pierre.weis@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=postmaster@jdh30.plus.com \
    /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).