- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Type system hackery question (has this been fixed for 2.8?)
Thu, 2009-04-16, 00:52
Hello, I have a class which is basically an HList, but instead of each type being an A, it is a Foo[A] { def get: A; ... other methods }. I'll call this a FooList. I'd like to be able to convert between a FooList and an HList by calling .get on each element in the FooList and I want the result to be of the proper type. Here's the FooList defintion:
sealed trait FooList {
case class FooNil extends FooList
case class FooCons[H,T<:FooList](head: Foo[H], tail: T) extends FooList
Ok, so far so good - now to allow conversion between this and an HList - I added an abstract type member to FooList, named HListForm, to store the corresponding HList type for each FooList. My evil plan was to simply convert the FooList to a List[Any] (simple), then call map(_.get) on this list, convert it to an HList, and then finally cast it to the type HListForm:
sealed trait FooList {
type HListForm <: HList
}
case class FooNil extends FooList {
type HListForm = HNil }
case class FooCons[H,T<:FooList](head: Foo[H], tail: T) { type HListForm = HCons[H,T#HListForm] }
... except I get an error "illegal cyclic reference involving type HListForm". I understand there's a ticket to "Allow recursive type projections" (http://lampsvn.epfl.ch/trac/scala/ticket/1291) but I'm not sure this is the same issue.
For reference, here's the HList impl - (somewhat impoverished)
sealed trait HList
case class HNil extends HList
case class HCons[H,T<:HList](head: H, tail: T) extends HList
Paul
Thu, 2009-04-16, 09:27
#2
Re: Type system hackery question (has this been fixed for 2.8?)
Paul Chiusano wrote:
> ... except I get an error "illegal cyclic reference involving type
> HListForm". I understand there's a ticket to "Allow recursive type
> projections" (http://lampsvn.epfl.ch/trac/scala/ticket/1291) but I'm not
> sure this is the same issue.
Have you tried the -Yrecursion switch?
There's an implementation of HList in Scala at:
http://trac.assembla.com/metascala/browser/src/metascala/HLists.scala
Maybe that can help you.
/Jesper Nordenberg
Thu, 2009-04-16, 11:57
#3
Re: Re: Type system hackery question (has this been fixed for
Is there a chance that this type system feature will to be turned on by default in 2.8?
Szymon
On Thu, Apr 16, 2009 at 10:22 AM, Jesper Nordenberg <megagurka@yahoo.com> wrote:
--
ʎɐqǝ uo pɹɐoqʎǝʞ ɐ ʎnq ı ǝɯıʇ ʇsɐן ǝɥʇ sı sıɥʇ
Szymon
On Thu, Apr 16, 2009 at 10:22 AM, Jesper Nordenberg <megagurka@yahoo.com> wrote:
Paul Chiusano wrote:
... except I get an error "illegal cyclic reference involving type HListForm". I understand there's a ticket to "Allow recursive type projections" (http://lampsvn.epfl.ch/trac/scala/ticket/1291) but I'm not sure this is the same issue.
Have you tried the -Yrecursion switch?
There's an implementation of HList in Scala at:
http://trac.assembla.com/metascala/browser/src/metascala/HLists.scala
Maybe that can help you.
/Jesper Nordenberg
--
ʎɐqǝ uo pɹɐoqʎǝʞ ɐ ʎnq ı ǝɯıʇ ʇsɐן ǝɥʇ sı sıɥʇ
Thu, 2009-04-16, 12:07
#4
Re: Re: Re: Type system hackery question (has this been fixed
On Thu, Apr 16, 2009 at 12:53 PM, Szymon Jachim wrote:
> Is there a chance that this type system feature will to be turned on by
> default in 2.8?
>
I doubt it. We still need to think things through thoroughly to be
clear of all the possible consequences before we fiddle with that in
the defaults. And there's lots of other things to do for 2.8. Maybe
sometimes after that...
Cheers
Thu, 2009-04-16, 19:57
#5
Re: Re: Type system hackery question (has this been fixed for
-Yrecursion worked for me with 2.7.4 RC. I can't figure out how to enable that flag in the NetBeans plugin though.
On Thu, Apr 16, 2009 at 4:22 AM, Jesper Nordenberg <megagurka@yahoo.com> wrote:
Paul Chiusano wrote:
... except I get an error "illegal cyclic reference involving type HListForm". I understand there's a ticket to "Allow recursive type projections" (http://lampsvn.epfl.ch/trac/scala/ticket/1291) but I'm not sure this is the same issue.
Have you tried the -Yrecursion switch?
There's an implementation of HList in Scala at:
http://trac.assembla.com/metascala/browser/src/metascala/HLists.scala
Maybe that can help you.
/Jesper Nordenberg
On Wed, Apr 15, 2009 at 7:51 PM, Paul Chiusano <paul.chiusano@gmail.com> wrote: