Re: [ceylon-users] Enumerated objects with type parameters

41 views
Skip to first unread message
Message has been deleted

Paco Soberón

unread,
Sep 27, 2017, 12:53:37 PM9/27/17
to ceylon...@googlegroups.com
Well, the problematic part is "of genEnum" in the definition of Enum<Gen>. What the error is saying is that genEnum satisfies Enum<String>, but not Enum<Gen> for every Gen.

El 27 sept. 2017 12:13 p. m., "Voitech" <wojciech...@gmail.com> escribió:
Hello I'm in need to have my enumerated objects to have type parameters. It should expose this parameters to satisfied interface. Example:

shared interface IFace<Gen> {}
shared
abstract class Enum<Gen>() of genEnum satisfies IFace<Gen> {}
shared
object genEnum extends Enum<String>() {}

This dosn't compile with error:
Case type must be a subtype of enumerated type for every type argument of the generic enumerated type: genEnum is not assignable to Enum<Gen>

Err why ? I don't understand.

Thank You
Voitech

--
You received this message because you are subscribed to the Google Groups "ceylon-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceylon-users+unsubscribe@googlegroups.com.
To post to this group, send email to ceylon...@googlegroups.com.
Visit this group at https://groups.google.com/group/ceylon-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceylon-users/a626d4fa-d2d9-4547-bf77-a3d0f1aaaf80%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gavin King

unread,
Sep 27, 2017, 1:04:22 PM9/27/17
to ceylon...@googlegroups.com
So the restrictions applying here are described in §3.4.3 of the
language specification:

https://ceylon-lang.org/documentation/1.3/spec/html/typesystem.html#genericenumeratedtypes

The feature you're looking for here is called "GADT" (Generalized
Algebraic Data Types) but Ceylon doesn't support them today.


On Wed, Sep 27, 2017 at 6:13 AM, Voitech <wojciech...@gmail.com> wrote:
> Hello I'm in need to have my enumerated objects to have type parameters. It
> should expose this parameters to satisfied interface. Example:
>
> shared interface IFace<Gen> {}
> shared abstract class Enum<Gen>() of genEnum satisfies IFace<Gen> {}
> shared object genEnum extends Enum<String>() {}
>
> This dosn't compile with error:
>>
>> Case type must be a subtype of enumerated type for every type argument of
>> the generic enumerated type: genEnum is not assignable to Enum<Gen>
>
>
> Err why ? I don't understand.
>
> Thank You
> Voitech
>
> --
> You received this message because you are subscribed to the Google Groups
> "ceylon-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ceylon-users...@googlegroups.com.
> To post to this group, send email to ceylon...@googlegroups.com.
> Visit this group at https://groups.google.com/group/ceylon-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ceylon-users/a626d4fa-d2d9-4547-bf77-a3d0f1aaaf80%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Gavin King
ga...@ceylon-lang.org
@1ovthafew

http://ceylon-lang.org
http://hibernate.org
http://seamframework.org

Gavin King

unread,
Sep 27, 2017, 1:05:50 PM9/27/17
to ceylon...@googlegroups.com
Of course, you can get your code to compile by removing "of genEnum"
but of course that's still not going to give you a GADT.

Lucas Werkmeister

unread,
Sep 27, 2017, 1:28:28 PM9/27/17
to ceylon...@googlegroups.com

You can also get it to compile by moving the type argument up by one level:

shared interface IFace<Gen> {}
shared abstract class Enum() of genEnum satisfies IFace<String> {}
shared object genEnum extends Enum() {}

But that only works as long as you only have one case type (or several, but all with the same Gen type argument).
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages