TSa (Thomas Sandlaß)
Wed, 27 Jul 2005 01:16:36 -0700
Ingo Blechschmidt wrote:
Hi,
ReHi,
are the following assumptions correct?
I don't know in general. But see my assumptions below for comparison. They are derived from my type theoretic approach and as such might collide with Perl6's referential semantics. In particular with the auto-ref/deref and how far it follows links.
sub foo ([EMAIL PROTECTED]) { @args[0] }
say ~foo("a", "b", "c"); # "a"
foo( List of Str )
my @array = <a b c d>; say ~foo(@array); # "a b c d" (or "a"?)
foo( Ref of Array ) # @args[0] derefs the array ref
# I guess you need @args[0][0] to get "a"
But I don't like this level of reference preservation.
E.g. one then needs to know how far out the flat array
resides, to use the right number of dereferencers. Here
type theory doesn't constrain the definitional freedom
because both interpretations are compatible with [EMAIL PROTECTED]
Actually that unspecificity could be preserved, see below.
say ~foo(@array, "z"); # "a b c d" (or "a"?)
foo( Ref of Array, Str ) # @args[0] as above Here typing constrains the interpretation to be the one that needs @args[0][0] to get at "a". This is slightly untrue. The problem is actually shifted to the question: "How does comma handle a Ref of Array?".
say ~foo([EMAIL PROTECTED]); # "a"
foo( List of Str build from Array of Str)
say ~foo(*(@array, "z")); # "a"sub bar ([EMAIL PROTECTED]) { [EMAIL PROTECTED] } say bar(1,2,3); # 3 say bar(@array); # 1 (or 4?)
Type theory actually should come up with any(1|4) :) And yes, any(1|4) is a type literal and any($x,$y) is a parametric type which is fixed whenever $x and $y are. Side node: A nice test for hidden assumptions in code is to replace functions which return Any to behave randomly. A Vogon optimizer OTOH, might blow away a complete planet and return 42 everywhere :) For this very reason the default signature of the ideal sub is of course ::Any --> ::All where All is pure specificity. And---even thow I should start a 'type theory foundations of Perl6' thread, I mention it here---the ideal method is ::All . ::Any --> ::All A multi sub/method is in that view a *metric* dispatcher on the middle ::Any between the selector before the dot and the return type after the arrow.
say bar(@array, "z"); # 2 (or 5?)
I opt for 2.
say bar([EMAIL PROTECTED]); # 4
Yep. -- TSa (Thomas Sandlaß)