Current State of Closures
Dr Andrew John Hughes
ahughes at redhat.com
Mon Jul 26 16:42:09 PDT 2010
Will the following be possible now or in the future as part of Project Lambda?
public class TestClosures
{
public static #Integer(Integer) partial(#Integer(Integer, Integer)
func, int arg1)
{
return func.(Integer.valueOf(arg1));
}
public static void main(String[] args)
{
#Integer(Integer,Integer) pow = #(Integer x, Integer y)(x * y);
#Integer(Integer) part = partial(pow, 2);
System.out.println(part.(2));
}
}
i.e. being able to supply a partial set of arguments to a method so
that a new method is returned.
In Haskell,
> :t (\x -> \y -> x * y)
(\x -> \y -> x * y) :: (Num a) => a -> a -> a
> :t (\x -> \y -> x * y) 2
(\x -> \y -> x * y) 2 :: (Num a) => a -> a
Currently this gives:
TestClosures.java:5: lambda expression cannot be applied to given types
return func.(Integer.valueOf(arg1));
^
required: Integer,Integer
found: Integer
--
Andrew :-)
Free Java Software Engineer
Red Hat, Inc. (http://www.redhat.com)
Support Free Java!
Contribute to GNU Classpath and the OpenJDK
http://www.gnu.org/software/classpath
http://openjdk.java.net
PGP Key: 94EFD9D8 (http://subkeys.pgp.net)
Fingerprint: F8EF F1EA 401E 2E60 15FA 7927 142C 2591 94EF D9D8
More information about the lambda-dev
mailing list