HaloO,
chromatic wrote:
What are marked semantic meanings?
Types. That is, in the context of "Dog", "bark" means "emit a sound". In the
context of "Tree", "bark" means "the outer skin".
Note that the only things that carry meaning in your other example
my $result = $thingie.bark;
are the English words in it. If you randomize all your identifiers
the impression of meaning is almost gone.
my $xgdfhls = $hrigo.ksjxkcj;
The only thing left is that a variable is initialized with the
return value of a method called on another variable. With more
type annotation the two bark methods can be distinguished with
higher probability.
my Sound = $thingie.bark;
versus
my Bark = $thingie.bark;
One problem with duck typing is specific to the language used for the
Identifiers. E.g. in German you have bark === Rinde|bellen. But there
e.g. Himmel === heaven|sky. So, if we had some meta identifier space
that guarantees uniqueness and allows hooking-in localized translations
you could translate
my $result = $thingie.bark;
to German either as
mein $Ergebnis = $Ding.bellen;
or
mein $Ergebnis = $Ding.Rinde;
A similar problem to the linguistic one above is that structural
identity by far doesn't mean conceptual identity. Take e.g. the
arrow type :(Num --> Num). It might be sufficient for a routine that
graphs the function, or this graphing might require e.g.
differentiability or continuity. How would you say that in Perl 6?
role Continuous does Code:(Num --> Num) { }
looks promising even though I see no way that the type checker
can enforce anything here. But let's trust the programmer who
composes the role into her functions. Now
sub graph ( &func where {.does: Continuous}, Num $from, Num $to )
{...}
sub square ( Num $x --> Num ) does Continuous { return $x * $x }
graph( &square, -10.0, 10.0 ); # type correct
The odd thing to me is that graph cannot be defined as
sub graph ( Continuous &func, Num $from, Num $to ) {...}
or is that the same? Then how do I get what I want? I think S06 says
that the above means that &func returns a Continuous value as in
sub foo ( Int &func:(Int) --> Int) { return func(17); }
sub double (Int $x --> Int) { return 2 * $x; }
say foo( &double ); # prints 34
My idea is that foo:( Foo &f ) should mean the same as
foo:( Foo $x ), that is the variables have to contain a
value that does Foo. Note that this implies that
sub mysub {...}
occupies two slots in the surrounding namespace &mysub and
::mysub. The latter is a type that can be used as
sub mysubuser ( mysub &f ) {...}
sub yoursub does mysub {...}
mysubuser( &yoursub ); # OK
sub blahh (Int $x) does mysub {...} # composition error
Regards, TSa.
--
"The unavoidable price of reliability is simplicity" -- C.A.R. Hoare
1 + 2 + 3 + 4 + ... = -1/12 -- Srinivasa Ramanujan