[swift-evolution] Reconsidering the (Element -> T?) variant of SequenceType.flatMap

Dmitri Gribenko gribozavr at gmail.com
Fri Dec 4 18:01:49 CST 2015


On Fri, Dec 4, 2015 at 4:00 PM, Maxwell Swadling <maxs at apple.com> wrote:
>
>> On 4 Dec 2015, at 3:37 PM, Dmitri Gribenko <gribozavr at gmail.com> wrote:
>>
>> On Fri, Dec 4, 2015 at 3:34 PM, Kevin Ballard <kevin at sb.org> wrote:
>>> Personally, I'd be in favor of making Optional conform to SequenceType. I've filed a radar on it before, and I seem to recall a message (probably to this list) yesterday suggesting the exact same thing.
>>
>> This would be an interesting direction, but we have discussed it a
>> long time ago, and found an issue in the way it would interact with
>> implicit promotions to optionals.  Basically, in a call to a function
>> accepting a Sequence, one would be able to write any non-sequence,
>> non-optional value, that would be implicitly promoted to optional, and
>> thus eligible to be passed as a Sequence.  This is the only argument
>> for not adding this conformance that I know of, but it is a show
>> stopper unfortunately.
>>
>> Dmitri
>>
>> --
>> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
>> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>
> I can not reproduce this behaviour. I'm not sure which version of the compiler had this behaviour.

The fact that the compiler does not do it means it is not implementing
the language model.  The compiler is not the source of truth about the
language, or we wouldn't have any bugs -- they all would be features.

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/


More information about the swift-evolution mailing list