From: Jon Harrop <jon@ffconsultancy.com>
To: skaller <skaller@users.sourceforge.net>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Custom operators in the revised syntax
Date: Sat, 12 May 2007 06:59:49 +0100 [thread overview]
Message-ID: <200705120659.49753.jon@ffconsultancy.com> (raw)
In-Reply-To: <1178948713.14691.89.camel@rosella.wigram>
On Saturday 12 May 2007 06:45, you wrote:
> On Sat, 2007-05-12 at 05:47 +0100, Jon Harrop wrote:
> > > 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.
> >
> > AFAIK, you just change the unify to intersect sets of types.
>
> I have no idea how to unify in the presence of (undiscriminated)
> setwise union of polymorphic types. It seems a little easier
> if the types are restricted to a finite set of non-polymorphic
> types.
They are, aren't they? e.g. int or float.
If you write:
> let ipow3 x =
let sqr x = x*x in
x * sqr x;;
val ipow3 : int -> int
then F# gives the inner definition "sqr" a type like [int|float] as 'a -> 'a
until it is resolved to int -> int. If you change the code with an outer
annotation:
> let ipow3 x : float =
let sqr x = x*x in
x * sqr x
val ipow3 : float -> float
then it still works because the inner type specializes to float -> float
rather than defaulting to int -> int. The outer definition of "ipow3" then
becomes float -> float.
> If ANYONE knows an algorithm that can do unification with
> sets of types, that is, with a union type, I'd sure like
> to know it!
Isn't this exactly what polymorphic variants do?
> > I hadn't thought of that. I just discovered that you cannot add vectors
> > of vectors in F#, so it is probably 1st order only.
>
> Hmm, that's a bit surprising if your explanation above is correct,
> that is, if it resorts to dynamic typing if it can't resolve
> statically.
I don't think it resorts to dynamic typing. I think it just doesn't do static
code explosion as C++ templates do. That isn't dynamic typing because the
types are still checked statically.
I believe the F# standard library also does some run-time type based
optimizations, like using specialized routines for vectors and matrices of
floats. Again, this isn't really dynamic typing because it does not introduce
any run-time errors.
So if you do:
type 'a complex = {r: 'a; i: 'a}
let zero_float = {r=0.; i=0.}
let zero_float32 = {r=0.f; i=0.f}
then it doesn't generate type specialized code for float and float32 (same as
OCaml). When you do:
List.map ((+) 1)
OCaml does not use a version of List.map that is specialized for ints.
That isn't to say that the .NET JIT won't do the specialization itself, but I
believe it does not currently do that.
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
The F#.NET Journal
http://www.ffconsultancy.com/products/fsharp_journal/?e
next prev parent reply other threads:[~2007-05-12 6:05 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 [this message]
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=200705120659.49753.jon@ffconsultancy.com \
--to=jon@ffconsultancy.com \
--cc=caml-list@yquem.inria.fr \
--cc=skaller@users.sourceforge.net \
/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