RE: Idea: infer types of constants

2008-04-15 Thread Miller, Hugh
 

>-Original Message-
>From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On 
>Behalf Of Mark J. Reed
>Sent: Monday, April 14, 2008 2:05 PM
>To: Jonathan Worthington
>Cc: David Green; Perl6
>Subject: Re: Idea: infer types of constants
>
>On Mon, Apr 14, 2008 at 2:32 PM, Jonathan Worthington
>>  my Dog $fifi .= new(); # works in Rakudo too ;-)
>
>And even in Pugs! :)  Doesn't help with literals, though, e.g.
>
>my Float $approx_pi = 3.14;
>
>
>
>--
>Mark J. Reed <[EMAIL PROTECTED]>
>

What about the type support (system) one sees in ML ? (e.g., the way it
assigns automatically types can be assigned, does not require specific
types when they are not needed, flags incompatibilities, etc.) Do those
things not fit well with Perl's approaches and aims ? 


Re: Idea: infer types of constants

2008-04-15 Thread Jonathan Worthington

TSa wrote:

Jonathan Worthington wrote:

Miller, Hugh wrote:

Was that private communication or on another mailing list?
It was also sent to perl6-language, through I was on the To or Cc line 
too, so I guess that's how I got it but the list, somehow, didn't. Not 
sure why the original message I replied to didn't actually make it to 
the list, though.



That should be $CALLER::a because $OUTER::a is the outer
lexical scope where foo is defined. 

Yup, sorry, brain only half working at this time of day. :-)

And I think that this reaching out to the caller should taint foo in 
some way.
Sure, but from what I can see that still doesn't help us infer types at 
compile-time if what foo means can be modified at runtime.


Jonathan


Re: Idea: infer types of constants

2008-04-15 Thread Jonathan Worthington

Miller, Hugh wrote:

What about the type support (system) one sees in ML ? (e.g., the way it
assigns automatically types can be assigned, does not require specific
types when they are not needed, flags incompatibilities, etc.) Do those
things not fit well with Perl's approaches and aims ? 
  
They don't really fit with Perl 6 too well. For example, suppose we 
tried to type inference this:


my $a = 42;
foo();
my $b = $a;

What is the type of $b? Well, we can't actually infer that because foo 
might be:


sub foo() {
   $OUTER::a = "oh hi, i iz not int!"
}

And because subs can be wrapped at runtime, or symbol tables can be 
diddled, or other such fun, we probably can't safely look at foo at 
compile time in the general case to make sure our inference is correct 
too, because foo might not be the foo we thought it was at compile time 
by the time we reach runtime.


From what I can see, making a language where the types are inferable, 
like ML, can almost involve doing the language design on a knife edge. 
You need the inference to not only be decidable, but also reasonably 
efficient, and a subtle feature interaction can hurt this (I think ML 
nearly had one of these when ref types and let statements interacted in 
a way that could compromise type safety - I'm rusty on the details). And 
if I'm remembering correct, there are contrived programs you can write 
that make the ML checker go exponential order in the size of the code too.


Jonathan



Re: Idea: infer types of constants

2008-04-15 Thread TSa

HaloO,

Jonathan Worthington wrote:

Miller, Hugh wrote:


Was that private communication or on another mailing list?


What is the type of $b? Well, we can't actually infer that because foo 
might be:


sub foo() {
   $OUTER::a = "oh hi, i iz not int!"
}


That should be $CALLER::a because $OUTER::a is the outer
lexical scope where foo is defined. And I think that this
reaching out to the caller should taint foo in some way.


Regards, TSa.
--

The Angel of Geometry and the Devil of Algebra fight for the soul
of any mathematical being.   -- Attributed to Hermann Weyl


Re: Idea: infer types of constants

2008-04-15 Thread TSa

HaloO,

John M. Dlugosz wrote:

Then the declaration

  my ::T $x = whatever;

should use the exact same generic mechanism!  At worst, it needs


I would expect that this works by binding ::T to the type of whatever.



  my Any ::T $x = whatever;


Any here is optional.


and it will introduce the T symbol at that point based on the actual 
type of what gets initialized.


Yes. But the problem is that this does *not* fix the constraint
of $x to be T from there on! Or does it?

   my ::T $x = 'blahh';  #  ::T ::= Str

   my T $y = 'blubb';

   $x = 23; # legal
   $y = 42; # illegal

So perhaps one needs

   my ::T T $x = 'blahh';

to constrain $x to the type of the rhs.


Regards, TSa.
--

The Angel of Geometry and the Devil of Algebra fight for the soul
of any mathematical being.   -- Attributed to Hermann Weyl


Re: Idea: infer types of constants

2008-04-14 Thread John M. Dlugosz

Mark J. Reed markjreed-at-mail.com |Perl 6| wrote:

On Mon, Apr 14, 2008 at 2:32 PM, Jonathan Worthington
  

 my Dog $fifi .= new(); # works in Rakudo too ;-)



And even in Pugs! :)  Doesn't help with literals, though, e.g.

my Float $approx_pi = 3.14;



  
So the idea of marking the use of implicit type would be better than 
making it automatic in some cases and not in others.  Logically, that is 
just a symbol like ::?TYPERHS but with more syntactic sugar, such as a 
special symbol:


 my ☂ $approx_pi = 3.14;

Where the umbrella is meant to convey the protective nature.  For those 
who don't have umbrella keys on their keyboards, you might consider the 
useless "window" buttons near the spacebar, or invest in one of these 
(http://piengineering.com/xkeys/xkstick.php). 

More seriously, reusing existing symbols and concepts, a generic type is 
introduced using ::T, in a signature.  The stuff after 'my' is actually 
a signature, so if


  sub foo (::T $a)

actually works (⦃and it might not -- still need to hear from Larry about 
leaving off the other type, you might have to write   sub foo (Any ::T $a) ⦄

Then the declaration

  my ::T $x = whatever;

should use the exact same generic mechanism!  At worst, it needs

  my Any ::T $x = whatever;

and it will introduce the T symbol at that point based on the actual 
type of what gets initialized.


--John


Re: Idea: infer types of constants

2008-04-14 Thread Mark J. Reed
On Mon, Apr 14, 2008 at 2:32 PM, Jonathan Worthington
>  my Dog $fifi .= new(); # works in Rakudo too ;-)

And even in Pugs! :)  Doesn't help with literals, though, e.g.

my Float $approx_pi = 3.14;



-- 
Mark J. Reed <[EMAIL PROTECTED]>


Re: Idea: infer types of constants

2008-04-14 Thread Jonathan Worthington

Mark J. Reed wrote:

I don't care for the use of * there, but it would be nice to have some
way to declare the variable to have the type implied by its
initializer, where the complier can tell what that is, so you could
remove the redundancy in this:

my Dog $fido = new Dog();

while still allowing the var declared via

my $fifi = new Dog();

Oo be untyped.
  

my Dog $fifi .= new(); # works in Rakudo too ;-)

Jonathan



Re: Idea: infer types of constants

2008-04-14 Thread Mark J. Reed
I don't care for the use of * there, but it would be nice to have some
way to declare the variable to have the type implied by its
initializer, where the complier can tell what that is, so you could
remove the redundancy in this:

my Dog $fido = new Dog();

while still allowing the var declared via

my $fifi = new Dog();

Oo be untyped.


On 4/14/08, David Green <[EMAIL PROTECTED]> wrote:
> On 2008-Apr-13, at 4:07 am, John M. Dlugosz wrote:
> > I'm thinking that 'constant' is more special than other variables,
> > and that the formal description of strong typing and static types
> > should say that the compiler =will= implicitly get the type for $pi
> > rather than making it Any.
>
> Except if constants infer their type and other variables don't, that's
> one more special case to remember.  What if there were a quick and
> unobtrusive way to get the type of the value instead of "Any"?  Can we
> use a "whatever" type?
>
>  my * $x = 12.34;# my Num $x
>  my * $y = "abc";# my Str $y
>  const * $z = $foobar;   # const Foo::Bar $z
>
>
> -David
>
>

-- 
Sent from Gmail for mobile | mobile.google.com

Mark J. Reed <[EMAIL PROTECTED]>


Re: Idea: infer types of constants

2008-04-14 Thread David Green

On 2008-Apr-13, at 4:07 am, John M. Dlugosz wrote:
I'm thinking that 'constant' is more special than other variables,  
and that the formal description of strong typing and static types  
should say that the compiler =will= implicitly get the type for $pi  
rather than making it Any.


Except if constants infer their type and other variables don't, that's  
one more special case to remember.  What if there were a quick and  
unobtrusive way to get the type of the value instead of "Any"?  Can we  
use a "whatever" type?


my * $x = 12.34;# my Num $x
my * $y = "abc";# my Str $y
const * $z = $foobar;   # const Foo::Bar $z


-David