Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jon Harrop <jon@ffconsultancy.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Scripting in ocaml
Date: Fri, 22 Dec 2006 15:20:30 +0000	[thread overview]
Message-ID: <200612221520.30939.jon@ffconsultancy.com> (raw)
In-Reply-To: <1166755864.6135.70.camel@rosella.wigram>

On Friday 22 December 2006 02:51, skaller wrote:
> Just BTW .. it is very bad to raise exceptions on type errors.

For what definition of "type"?

> The reason is that raising such exceptions also allows for
> catching them, which means doing a type error is no longer
> unsafe and no longer a bug, but a legitimate technique.
> This in turn defeats most static type analysis you might do.

Absolutely. But the ability to do run-time dispatch based upon type is an 
advantage of dynamic typing, so it is something that you do not want to lose.

> For example this destroys the ability to analyse Python
> statically for the purpose of optimising it.

Yes. An optimising Python compiler will only be adopted/useful if it can 
evaluate any Python. Note that this could mean reverting to interpreted 
bytecode when the program is inherently dynamically typed.

> It is *essential* that the language description not
> mandate raising exceptions on type errors, but rather
> specify the action is undefined .. even if the implementation
> raises an exception, the language specification must NOT
> require that. This prevents programmers actually relying on it
> and allows a static analyser to optimise the code on the
> assumption it is well typed.

You can raise exceptions from unexpectedly typed code whilst keeping the 
advantages of static checking and performance in F#, for example. This gives 
you the advantages of both worlds: performance/reliability when leveraging 
static typing and brevity/generality when leveraging dynamic typing.

For example, I recently benchmarked C++, F#, OCaml and Python for computing 
discrete wavelet transforms. F# (on 32-bit WXP) was slightly faster than 
OCaml (on 64-bit Debian), so it can have very competitive performance:

http://groups.google.co.uk/group/comp.lang.python/msg/0229d2c6484ea491?hl=en&
http://groups.google.co.uk/group/comp.lang.python/msg/daf7bbb2bd7e99f3?hl=en&

Yet F# retains run-time type information so you can use a generic print 
function (print_any) on any type, have your dynamic code loading and so on. 
The best of both worlds.

On a related note, F# supports operator overloading, which greatly simplifies 
many mathematical expressions at the cost of requiring more type annotations.

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists


  reply	other threads:[~2006-12-22 15:22 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-21  3:41 Denis Bueno
2006-12-21  4:34 ` [Caml-list] " Erik de Castro Lopo
2006-12-21  7:22   ` skaller
2006-12-21  9:12     ` Till Varoquaux
2006-12-21  9:18     ` Chad Perrin
2006-12-21 10:29       ` skaller
2006-12-21 20:21         ` Chad Perrin
2006-12-21 13:30     ` Serge Aleynikov
2006-12-21 13:52       ` skaller
2006-12-21 14:59         ` Serge Aleynikov
2006-12-21 20:25           ` Chad Perrin
2006-12-21 20:41             ` Daniel Bünzli
2006-12-21 22:16               ` Chad Perrin
2006-12-22 12:21                 ` strong/weak typing terminology (was Re: [Caml-list] Scripting in ocaml) Daniel Bünzli
2006-12-22 16:51                   ` Tom
2006-12-22 17:34                     ` Daniel Bünzli
2006-12-22 18:16                     ` skaller
2006-12-22 18:47                       ` Daniel Bünzli
2006-12-22 19:42                         ` skaller
2006-12-22 20:03                           ` David Brown
2006-12-22 20:17                             ` Chad Perrin
2006-12-23  3:48                               ` skaller
2006-12-23  4:11                                 ` Chad Perrin
2006-12-22 20:19                           ` Chad Perrin
2006-12-23 12:58                           ` Daniel Bünzli
2006-12-23 16:06                             ` Chad Perrin
2006-12-23 21:50                               ` Tom
2006-12-26  6:10                                 ` Chad Perrin
2006-12-22 20:14                   ` Chad Perrin
2006-12-21 21:11             ` [Caml-list] Scripting in ocaml Serge Aleynikov
2006-12-21 21:27               ` Philippe Wang
2006-12-21 22:06                 ` Serge Aleynikov
2006-12-22 12:35                 ` Jon Harrop
2006-12-21 22:19               ` Chad Perrin
2006-12-22 12:37                 ` Jon Harrop
2006-12-22 18:52                   ` Chad Perrin
2006-12-22  2:51               ` skaller
2006-12-22 15:20                 ` Jon Harrop [this message]
2006-12-22 11:32               ` Jon Harrop
2006-12-23 18:50           ` Jon Harrop
2006-12-24  0:15             ` Serge Aleynikov
2006-12-24  3:30             ` skaller
2006-12-21 14:59 ` Richard Jones
2006-12-21 20:27   ` Chad Perrin
2006-12-21 23:35   ` Martin Jambon
2006-12-26 17:14 ` Aleksey Nogin
2006-12-26 23:36   ` Ian Zimmerman
2006-12-27 18:25     ` Aleksey Nogin
2006-12-27 18:39       ` Richard Jones
2006-12-27 19:20         ` Aleksey Nogin

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=200612221520.30939.jon@ffconsultancy.com \
    --to=jon@ffconsultancy.com \
    --cc=caml-list@yquem.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