Re: Re: Curious about method handling

James Reeves <[email protected]> Sat, 6 Aug 2005 12:30:48 +0100
Newsgroups gmane.comp.lang.nice.general
Message-ID <[email protected]>
On Friday 05 Aug 2005 22:43, Artem Gr wrote:
> > This appears neater, but it contains a superfluous type. The compiler
> > doesn't need to know the class of the object the method belongs to. All
> > that should be necessary to know is the input types and output type of
> > the method.
>
> 'new A("Hello World")' is not a type, it's an instance of the type.
>  From what i see in your Python example, Python ignores the "input
> types" of the method, it generates an anonymous void->String method
> instead. I am not aware of such a syntactic sugar in Nice.

I meant that

void printOutput(A klass, A->String func );

has an extra type restrictriction over:

void printOutput(void->String func);

> That is becouse the "input types" of the "bye" method are different:
> method "greet" has "input types" of (A), and method "bye" has "input
> types" of (B), that is, compiler behaves exactly as you've said: it only
> cares about "input types and output type of the method".
>
> If the compiler should remember the first argument of a method (which is
> Spaceship or Game instance, in your example), why shouldn't it remember
> other other arguments as well?

An excellent point, and one that I hadn't considered. However, I've thought 
about it, and I have an answer:

Because Nice already treats the first argument as a special case.

Consider:

class A {}
class B { String name = "Bob"; }

void greet(A a, B b) {
  println( "Hello " b.name );
}

void main(String[] args) {
  A a = new A();
  B b = new B();
  greet(a, b); // valid
  a.greet(b); // valid
  b.a.greet(); // invalid
}

Only the first argument is treated as a 'container'. Subsequent arguments have 
no special syntax associated with them.

So it's in keeping with current syntax to allow some syntactic sugar to curry 
the first argument of a method.

Current Nice syntax:

a  => a
a()  => the return value of a
b.c  => the return value of c curried with b (i.e. c(b))
b.c()  => the return value of c curried with b

Suggested Nice syntax:

a  => a
a()  => the return value of a
b.c  => c curried with b
b.c()  => the return value of c curried with b

--
James Reeves
http://www.monkeyengines.co.uk/


-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf