Fwd: Types and Generics

---------- Forwarded message ---------
From: Dimitre Novatchev <dnovatchev@gmail.com>
Date: Mon, Nov 30, 2020 at 7:32 AM
Subject: Re: Types and Generics
To: Michael Kay <mike@saxonica.com>
Cc: Adam Retter <adam.retter@exquery.org>, Christian Grün <
christian.gruen@gmail.com>


> The type subsumption rules are defined in §2.5.6 -
https://www.w3.org/TR/xquery-31/#id-sequencetype-subtype
>
> This of course is the source of most problems with Java Generics - the
fact that List<Object> doesn't subsume List<String>. Perhaps we don't have
that problem because we don't have mutable collections; but the function
coercion
> rules are certainly going to be hard to get right.

If this was done in other languages, why can't we do it?

At least give it a try? :)

Thanks,
Dimitre

On Mon, Nov 30, 2020 at 7:15 AM Michael Kay <mike@saxonica.com> wrote:

> The type subsumption rules are defined in §2.5.6 -
> https://www.w3.org/TR/xquery-31/#id-sequencetype-subtype
>
> This of course is the source of most problems with Java Generics - the
> fact that List<Object> doesn't subsume List<String>. Perhaps we don't have
> that problem because we don't have mutable collections; but the function
> coercion rules are certainly going to be hard to get right.
>
> Michael Kay
> Saxonica
>
> On 30 Nov 2020, at 15:03, Dimitre Novatchev <dnovatchev@gmail.com> wrote:
>
>  >  But a fully worked specification (including, in particular, all the
> type subsumption rules)
> > is something that I don't have the energy (or probably the brain-power)
> for.
>
> Could you, please expand on this? Any examples of the "type subsumption
> rules" ?
>
> What do other developers / implementors think? @Christian Grün
> <christian.gruen@gmail.com>  @Adam Retter <adam.retter@exquery.org> ?
>
> Thanks,
> Dimitre
>
> On Mon, Nov 30, 2020 at 2:48 AM Michael Kay <mike@saxonica.com> wrote:
>
>> I've wondered about this; and internally, at a very simple level, Saxon
>> does have something a bit like this where we know, for example, that the
>> result of fn:reverse is the same type as the input. But a fully worked
>> specification (including, in particular, all the type subsumption rules) is
>> something that I don't have the energy (or probably the brain-power) for.
>>
>> Michael Kay
>> Saxonica
>>
>> On 30 Nov 2020, at 01:30, Dimitre Novatchev <dnovatchev@gmail.com> wrote:
>>
>> Isn't it time to introduce generics?
>>
>>
>> fn:group-by($seq as $$T*,
>>
>>             $fun as function($arg as $$T  ) as $$V)
>>         as map($$V, $$T+)
>>
>> Applies $fun on each of the items in $seq and groups the results by
>> value, in a  map with an entry for each distinct produced value $v  (as
>> key) and value - the sequence of all items $it in $seq such that $fun($it)
>> eq $v
>>
>>
>> Thanks,
>> Dimitre
>>
>>
>>
>>
>
>

Received on Monday, 30 November 2020 15:47:26 UTC