W3C home > Mailing lists > Public > public-script-coord@w3.org > October to December 2011

Re: [Bug 14188] Union types

From: Simon Pieters <simonp@opera.com>
Date: Wed, 14 Dec 2011 08:11:47 +0100
To: public-script-coord@w3.org, bugzilla@jessica.w3.org
Message-ID: <op.v6gwxxfjidj3kv@simon-pieterss-macbook.local>
On Wed, 14 Dec 2011 05:08:25 +0100, <bugzilla@jessica.w3.org> wrote:

> https://www.w3.org/Bugs/Public/show_bug.cgi?id=14188
>
> --- Comment #7 from Cameron McCormack <cam@mcc.id.au> 2011-12-14  
> 04:08:24 UTC ---
> Union types are not necessary for some simple overloading cases, like the
> various canvas methods
>
>   void drawImage(HTMLCanvasElement e, float x, float y);
>   void drawImage(HTMLImageElement e, float x, float y);
>
> although they would probably benefit from becoming more readable.
>
> They are necessary for the case that Anne brings up there, specifying  
> the type
> of the variadic arguments in an operation (unless you want to use "any").
> Similarly for the element type of sequence<T> and T[].
>
> But union types bring with them the same kinds of problems that  
> overloading
> does, namely how to select which of the constituent types is meant when  
> you
> need to convert values.
>
>   void f(Node or DOMString x);
>
> Do ToObject and check if it's a Node, or do a ToString and assume it's a
> DOMString?

Isn't ToObject unnecessary? If it is a Node, it wouldn't be converted. If  
it's not a Node, it still wouldn't be one after conversion.

I think it should first check if the argument matches one of the host  
object types, second matches one of the primitive types, and third convert  
to the first primitive type.

So for

void f(Node or WindowProxy or float or DOMString x);

f(node) // Node
f(window) // WindowProxy
f(1) // float
f("1") // DOMString
f({toString:function(){return "1"}}) // float

-- 
Simon Pieters
Opera Software
Received on Wednesday, 14 December 2011 07:12:39 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 8 May 2013 19:30:05 UTC