caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jon Harrop <jon@ffconsultancy.com>
To: "Nicolas Pouillard" <nicolas.pouillard@gmail.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Custom operators in the revised syntax
Date: Sat, 12 May 2007 11:09:22 +0100	[thread overview]
Message-ID: <200705121109.23192.jon@ffconsultancy.com> (raw)
In-Reply-To: <cd67f63a0705120249mad04b01qa8fb626d0cb399ff@mail.gmail.com>

On Saturday 12 May 2007 10:49, you wrote:
> What your system should do when encountering:
>
> let double x = x + x;;

F# ossifies global definitions to defaults (if any) or type errors. In this 
case:

  val double : int -> int

If the definition had been:

  let first a = a.[0];;

then there is no default and it would ask for clarification as to the type 
of "a" (is it an array, hash table, vector etc.).

> double 1;;

Fine.

> double 1.1;;
> double (Vector.from_array [| 1.1; 2.2; 3.3 |]);;

Both static type errors.

This seems to work very well by minimizing confusion, maximizing performance 
(everything is resolved statically) and letting me write mathematical 
expressions concisely.

If the definition of "double" is nested then its type is not ossified 
immediately but will unify to "int" at the application "double 1;;", so the 
next two calls are static type errors just as they are in OCaml.

There are other problems, like do we generalize from:

  val ( * ) : 'a -> 'a -> 'a

to:

  val ( * ) : 'a -> 'b -> 'c

e.g. "scalar * vector -> vector"?

You also have ambiguity with conventional syntax. Does "vector * vector" mean 
dot, cross or element-wise product?

Lessons can be learned from languages like Matlab, where people often 
accidentally add a scalar to each element of a vector (so we know that would 
be a useful type error).

Potentially, you could even overload "f x" to allow it to mean multiplication 
when "f" is a numeric and not a functional value. So the type could go 
through ['a -> 'b | int | float | ...].

I've written about 100k LOC of F# code now and I haven't had a single 
non-trivial type problem caused by overloading. So I'd definitely question 
the conventional view that overloading and inference do not sit well 
together. Worst case, the compiler asks for a type annotation...

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
The F#.NET Journal
http://www.ffconsultancy.com/products/fsharp_journal/?e


  reply	other threads:[~2007-05-12 10:14 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-10 20:55 Nicolas Pouillard
2007-05-10 21:35 ` [Caml-list] " Loup Vaillant
2007-05-10 22:25   ` Nicolas Pouillard
2007-05-11  6:52 ` Stefano Zacchiroli
2007-05-11 13:14 ` dmitry grebeniuk
2007-05-11 14:15   ` Loup Vaillant
2007-05-11 14:37     ` Jon Harrop
2007-05-11 14:46       ` Nicolas Pouillard
2007-05-12  2:48         ` Jon Harrop
2007-05-12  4:40           ` skaller
2007-05-12  4:47             ` Jon Harrop
2007-05-12  5:45               ` skaller
2007-05-12  5:59                 ` Jon Harrop
2007-05-12  6:43                   ` skaller
2007-05-12 10:22             ` Richard Jones
2007-05-13 15:42               ` Arnaud Spiwack
2007-05-13 16:04                 ` ls-ocaml-developer-2006
2007-05-13 20:08                   ` Nicolas Pouillard
2007-05-12  9:49           ` Nicolas Pouillard
2007-05-12 10:09             ` Jon Harrop [this message]
2007-05-11 14:52       ` Loup Vaillant
2007-05-11 18:32         ` skaller
2007-05-12  4:48         ` Jon Harrop
2007-05-11 18:23       ` skaller
2007-05-11 14:40     ` Nicolas Pouillard
2007-05-11 18:22     ` skaller
2007-05-11 14:36   ` Nicolas Pouillard
2007-05-11 14:47     ` brogoff
2007-05-11 14:51       ` Nicolas Pouillard
2007-05-11 18:25         ` brogoff
2007-05-11 20:37           ` Nicolas Pouillard
2007-05-12 22:54           ` Nicolas Pouillard
2007-05-13  0:27             ` ketti
2007-05-13  1:05               ` Christian Stork
2007-05-13 10:50                 ` Nicolas Pouillard
2007-05-13  5:52             ` brogoff
2007-05-13  7:36               ` skaller
2007-05-13 13:12                 ` Jacques Carette

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=200705121109.23192.jon@ffconsultancy.com \
    --to=jon@ffconsultancy.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=nicolas.pouillard@gmail.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).