Closed lizmat closed 11 years ago
Yes, using :type
and :of
named arguments to create typed hashes doesn't feel right to me either. For one, "type" is too generic a name, it should probably be :ofkey
or whatever the accessor of a hash's type ends up being.
Slightly better might be to pass along a prototype object used to construct the Hash (e.g., via ".new"), instead of specifying the of/key types independently.
Of course, in the final analysis, simply using .new() to create typed hashes would seem cleanest of all.
Pm
On May 21, 2013, at 3:04 PM, Patrick R. Michaud notifications@github.com wrote:
Yes, using :type and :of named arguments to create typed hashes doesn't feel right to me either. For one, "type" is too generic a name, it should probably be :ofkey or whatever the accessor of a hash's type ends up being.
Slightly better might be to pass along a prototype object used to construct the Hash (e.g., via ".new"), instead of specifying the of/key types independently.
Of course, in the final analysis, simply using .new() to create typed hashes would seem cleanest of all.
So you're saying you're not against using these typed parameters for Hash.new? So the only problem is the API change on hash() ?
Liz
According to the spec at S06:3298, confirmed more or less at S04:1639, you can only specify a list (positionals) for creating a hash.
However, hash() is currently implemented as allowing any mix of Positionals and Named parameters to create a hash. https://github.com/rakudo/rakudo/pull/156 makes the API of hash() consistent with Hash.new.
But apparently, this feels wrong: http://irclog.perlgeek.de/perl6/2013-05-20#i_7094884 .
So maybe the Spec should change on this. And should we find another way of creating "typed hashes" ?