develooper Front page | perl.perl6.language | Postings from May 2005

Re: reduce metaoperator on an empty list

Thread Previous | Thread Next
May 19, 2005 04:38
Re: reduce metaoperator on an empty list
Message ID:
Michele Dondi wrote:
> On Wed, 18 May 2005, Rob Kinyon wrote:
>>> 1) undef (which may or may not contain an exception), or
>>> 2) some unit/identity value that is a trait of the operator,

I think that the unit/identity/neutral value is a trait of the
operator *and* the type of the values which are expected from
the list/array. If nothing more specific is known it would be
Any ::= Str | Num | Ref | Array | Hash | Code | ...
of which I don't know what the neutral value for +, *, ~, etc.
should be.

>>> depending on whether or not people think (2) is actually a good idea.
>> I would think that the Principle of Least Surprise points to (1),

Me, too. In particualr since Perl6 has got rich undef semantics.
BTW, is an Undef type specified? Is it a one-below-Any type,
i.e. Any ::= ... | Undef | ...

> I don't think so. I, for one, would expect [+]; to return zero and [*]; 
> to return 1. But that's only because I {trust,expect} perl(6) to be 
> smart enough to DWIM.

I would expect the dwimmery beeing a natural outcome of the strong type
system :)
So, if neutral(+,Any) =:= 0 and +Any =:= Num and the empty list returns
any number of undefs you ask it to provide and +undef == 0 then [+];
gives 0. Same reasoning applies for [*] gives 1 and for [~] you get ''
when ~Any =:= Str. All that is more or less my way to repeat what others
have said in this thread.
$TSa =:= all( none( @Larry ), one( @p6l ))

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About