From: skaller <skaller@users.sourceforge.net>
To: Jon Harrop <jon@ffconsultancy.com>
Cc: Nicolas Pouillard <nicolas.pouillard@gmail.com>,
caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Custom operators in the revised syntax
Date: Sat, 12 May 2007 14:40:03 +1000 [thread overview]
Message-ID: <1178944803.14691.28.camel@rosella.wigram> (raw)
In-Reply-To: <200705120348.50308.jon@ffconsultancy.com>
On Sat, 2007-05-12 at 03:48 +0100, Jon Harrop wrote:
> Using, +, +., +| and +|| is better than add, add_float, add_vector, add_matrix
> but allowing + to be used to all such types ('a -> 'a -> 'a) is much better
> still. It isn't even that hard to add to the language.
Oh? It changes the way type inference works.
I have only seen one algorithm for this an it was
extremely complicated. If you know a better way I'd
sure like to know what it is.
Of course, you can use the Haskell typeclass approach,
where you make the signature predefined as:
(+): 'a -> 'a -> 'a
and then resolve to the specific type and thus specific
function (or error) after the usual inference/checking phase,
however this *does* require a extra code in the compiler,
possibly a complete extra phase that has to be done before
type information is erased, it introduces new errors:
let f a b = a + b
will pass type checking, then fail during instantiation,
whereas at present the signature is inferred as
f: int * int -> int
I know F# supports overloaded operators, but I have no idea
how it can work.
Felix also allows both overloading AND typeclasses,
but it works because it does not have type inference.
The only way I can see to extend Ocaml without breaking it
would require the introduction of a new kind of type,
which would at least allow finite sets of ground types,
for example:
int \U int16 \U int32 \U float \U bigint \U matrix
Felix actually has these things, they're not types
but nouns of sugar used for constraints:
'a constraint 'a = int | 'a = int16 ...
and this kind of constraint, unfortunately, doesn't propagate
(i.e. the above isn't really a type). Propagating ground
type sets is actually easy, but once you have higher orders
it is probably undecidable.
--
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net
next prev parent reply other threads:[~2007-05-12 4:40 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 [this message]
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
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=1178944803.14691.28.camel@rosella.wigram \
--to=skaller@users.sourceforge.net \
--cc=caml-list@yquem.inria.fr \
--cc=jon@ffconsultancy.com \
--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