Skolems are indeed synthetic type "constants" that are copies of existentially bound or universally bound type variables. E.g.if you are in the rhs a methoddef foo[T](x: T) = ... foo[List[T]]....the skolem named T refers to the unknown type instance of T when foo is called. It needs to be different from the type parameter because in a recursive call as in the foo[List[T]] above the type parameter gets substituted with List[T], but the type skolem stays what it is.The other form of skolem is an existential skolem. Say you have a functiondef bar(xs: List[T] forSome { type T }) = xs.headthe each occurrence of xs on the right will give have typeList[T'] where T' is a fresh copy of T.That's what we call an existential skolem. Hope this helps! - Martin
class Foo[T <: Foo[T]]so why this is not a problematic kind of recursion that not need to be solved with skolems?
this would allow us to get rid of the following mutations (off the top of my head -- there may be more):
I was discussing an alternative strategy with Paul regarding TypeVars, and potentially also skolems.The context was reducing mutation in the type checker.The idea would be to track a map from undetermined type parameter symbols to TypeConstraints in the Context (instead of just a list),
make subtyping (and related methods) context-sensitive (so that they can consult the undetparamToTypeConstraint map),this would allow us to get rid of the following mutations (off the top of my head -- there may be more):
- undoLog (push a new context on the stack when a subtype check must be undoable, pop it when done)
- the substitution of typerefs to typevars (simply populate the undetparams map with fresh type constraints)
- skolemisation (we'd be mutating the TypeConstraint in the current context rather than the method type param symbol's info)
- this would then work uniformly for class & method type params
- type var suspension (in findMember)
Maybe something to explore in dotty?
On Wednesday, July 18, 2012 5:17:22 AM UTC-7, martin wrote:On Mon, Jul 16, 2012 at 4:53 PM, Paul Phillips <pa...@improving.org> wrote:On Mon, Jul 16, 2012 at 7:40 AM, Grzegorz Kossakowski <grzegorz.k...@gmail.com> wrote:
class Foo[T <: Foo[T]]so why this is not a problematic kind of recursion that not need to be solved with skolems?It is a problematic kind of recursion, very much so: a whole bunch of bugs are tied up in it.For the different handling in method/class, I vaguely recall variance is a factor. It feels like one anyway.
I think we should and we tried but because of classes' open recursion it was too tough. Consequently, we allow GADT behavior only for method type parameters.So, in a nutshell, skolems support GADTs (because you can attach local information to a skolem without touching the type parameters).Cheers- Martin
It's a mouth-watering summary. I have been thinking along the same lines and it's great to see it all listed together. The main reason we cannot do it easily in the current nsc design is that contexts don't reach the isSubType method, and it would take a lot to change that.