Generic lower bound constraint

62 views
Skip to first unread message

Julien Viet

unread,
Jul 6, 2014, 10:19:49 AM7/6/14
to ceylo...@googlegroups.com
I read in the spec it is not part of the language.

I’m trying to express something like:

interface Observable<out Element> {
   ...
   Observable<U> reduce<U>(U accumulator(U u1, U u2)) given U “super” Element
}

I looked at Ceylon Iterable that uses a different pattern for expressing this case with the Result generic type. But that would not work well in my case.

Anyway I do not debate which way is the best, I want to know if lower bound constraint will be part of the language someday.


--
Julien Viet
www.julienviet.com


Gavin King

unread,
Jul 6, 2014, 12:29:17 PM7/6/14
to ceylo...@googlegroups.com
I don't think there is any problem at all with introducing lower bounds to the language; it would probably be quite a simple task to implement, and we reserved "abstracts" as a keyword just in case we decide we need it after all. But I've not so far run into a case that calls for it, so I'm very interested to know why you think the approach on Iterable.reduce() wouldn't work for you because it seems to me that it's virtually equivalent to what you wrote down below.

Sent from my iPhone
> --
> You received this message because you are subscribed to the Google Groups "ceylon-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ceylon-dev+...@googlegroups.com.
> To post to this group, send email to ceylo...@googlegroups.com.
> Visit this group at http://groups.google.com/group/ceylon-dev.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ceylon-dev/etPan.53b95b03.62bbd95a.9c%40juliens-mbp-2.
> For more options, visit https://groups.google.com/d/optout.

Julien Viet

unread,
Jul 6, 2014, 12:47:22 PM7/6/14
to Gavin King, ceylo...@googlegroups.com
cool.

I’m prototyping a Ceylon version of Netflix Rx.Java (a wrapper) and that would make the bridging easier.

--
Julien Viet
www.julienviet.com


On 6 Jul 2014 at 18:29:18, Gavin King (gavin...@gmail.com) wrote:
> I don't think there is any problem at all with introducing lower bounds to the language;
> it would probably be quite a simple task to implement, and we reserved "abstracts" as
> a keyword just in case we decide we need it after all. But I've not so far run into a case that
> calls for it, so I'm very interested to know why you think the approach on Iterable.reduce()
> wouldn't work for you because it seems to me that it's virtually equivalent to what you
> wrote down below.
>
> Sent from my iPhone
>
> > On 6 Jul 2014, at 4:19 pm, Julien Viet wrote:
> >
> > I read in the spec it is not part of the language.
> >
> > I’m trying to express something like:
> >
> > interface Observable {
> > ...
> > Observable reduce(U accumulator(U u1, U u2)) given U “super” Element
> > }
> >
> > I looked at Ceylon Iterable that uses a different pattern for expressing this case with
> the Result generic type. But that would not work well in my case.
> >
> > Anyway I do not debate which way is the best, I want to know if lower bound constraint will
> be part of the language someday.
> >
> >
> > --
> > Julien Viet
> > www.julienviet.com
> >
> >
> > --
> > You received this message because you are subscribed to the Google Groups "ceylon-dev"
> group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to ceylon-dev+...@googlegroups.com.
> > To post to this group, send email to ceylo...@googlegroups.com.
> > Visit this group at http://groups.google.com/group/ceylon-dev.
> > To view this discussion on the web visit https://groups.google.com/d/msgid/ceylon-dev/etPan.53b95b03.62bbd95a.9c%40juliens-mbp-2.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups "ceylon-dev"
> group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ceylon-dev+...@googlegroups.com.
> To post to this group, send email to ceylo...@googlegroups.com.
> Visit this group at http://groups.google.com/group/ceylon-dev.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ceylon-dev/A35251BC-3A8E-40B9-A760-58D9BCEA2FBE%40gmail.com.

Gavin King

unread,
Jul 6, 2014, 12:58:47 PM7/6/14
to Julien Viet, ceylo...@googlegroups.com
What does the Java signature look like?

Sent from my iPhone

Ross Tate

unread,
Jul 15, 2014, 3:23:58 PM7/15/14
to ceylon-dev, Julien Viet
Having a type parameter of a generic method be lower bounded by a covariant type parameter of the containing generic is actually quite a common trick (in certain communities) for supporting covariance while having non-covariant-in-style methods.


Gavin King

unread,
Jul 15, 2014, 4:40:43 PM7/15/14
to ceylo...@googlegroups.com, Julien Viet
Sure, but we don't need that because we have a competing pattern with
union types that usually actually gives much better results than a
lower bound would.
> https://groups.google.com/d/msgid/ceylon-dev/CABnofR7zA0XdfTYXPCFjBvzwWarjtspdQcOJooPu9VEK%3DQbopQ%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Gavin King
ga...@ceylon-lang.org
http://profiles.google.com/gavin.king
http://ceylon-lang.org
http://hibernate.org
http://seamframework.org
Reply all
Reply to author
Forward
0 new messages