Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support type lambdas that capture generic arguments #561

Open
jvasileff opened this issue May 21, 2015 · 0 comments
Open

support type lambdas that capture generic arguments #561

jvasileff opened this issue May 21, 2015 · 0 comments
Labels
Milestone

Comments

@jvasileff
Copy link
Member

In the code below, Functor has a generic parameter Container that takes type constructors of the form Container<Element>. This works well for types like Singleton, List, and Set.

Pair is a class with two generic parameters (Pair<A,B>) - one more of course than Container.

In order to satisfy Container with Pair, a type lambda is necessary to resolve this difference. PairLambda performs this task, capturing PairFunctor's A for Pair's first type parameter, and designating Pair's second type parameter as Container's Element.

This type checked code:

class Pair<A,B>() {}

interface Functor<Element, Container> 
        given Container<Element> {

    shared default void doSomething() {
        print(`Element`);
    }
}

class PairFunctor<A, B>() 
        satisfies Functor<B, PairLambda>
        given A satisfies Object {

    shared alias PairLambda<E> => Pair<A,E>;
}

void callDoSomething<Element, Container>
        (Functor<Element, Container> functor)
        given Container<Element> {

    functor.doSomething();
}

shared void testPairFunctor() {
    value functor = PairFunctor<Integer,Float>();
    functor.doSomething();
    callDoSomething(functor);
}

results in:

ceylon.language::Float
snapjs.base-0.0.1.js:5370
$16l1={t:Pair,a:{B$Pair:'E$PairLambda',A$Pair:pairFunctor$.$$targs$$.A$PairFun
                                                                    ^
TypeError: Cannot read property 'A$PairFunctor' of undefined
    at pairFunctor$.PairLambda$PairFunctor (snapjs.base-0.0.1.js:5370:138)
    at testPairFunctor (snapjs.base-0.0.1.js:5385:75)
    at [eval]:1:366

If PairLambda is rewritten to not capture PairFunctor.A, the program works. With:

    shared alias PairLambda<E> => Pair<String,E>;

you get:

ceylon.language::Float
ceylon.language::Float
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants