higher kinded types/type functions
Geoff Reedy <geoff <at> programmer-monk.net>
2008-04-01 18:14:04 GMT
I'm exploring some stuff inspired by the Type-level Church encodings
section of Towards Equal Rights for Higher-kinded Types and am
encountering some odd behavior.
Starting with the following definitions in the repl:
case class Equals[A, B >: A <: A]
trait hasT { type t <: hasT }
abstract class TypeHolder[T <: hasT] extends hasT { type t = T }
abstract class TNil extends hasT { type t = Nothing }
I try the following:
scala> Equals[TNil,TypeHolder[TNil]#t]
res4: Equals[TNil,TypeHolder[TNil]#t] = Equals()
scala> Equals[TNil,f[TypeHolder[TNil]]]
res5: Equals[TNil,f[TypeHolder[TNil]]] = Equals()
scala> Equals[TNil,TypeHolder[TypeHolder[TNil]]#t#t]
res6: Equals[TNil,TypeHolder[TypeHolder[TNil]]#t#t] = Equals()
scala> Equals[TNil,f[TypeHolder[TypeHolder[TNil]]#t]]
res7: Equals[TNil,f[TypeHolder[TypeHolder[TNil]]#t]] = Equals()
So far so good, but then I try switching the application of f and #t:
scala> Equals[TNil,f[TypeHolder[TypeHolder[TNil]]]#t]
<console>:10: error: illegal cyclic reference involving type t
Equals[TNil,f[TypeHolder[TypeHolder[TNil]]]#t]
^
As far as I can figure f[TypeHolder[TypeHolder[TNil]]]#t should be
equivalent to TypeHolder[TypeHolder[TNil]]#t#t and
f[TypeHolder[TypeHolder[TNil]]#t]
Even stranger is that after that error,
Equals[TNil,TypeHolder[TypeHolder[TNil]]#t#t] gives an error too where
it worked previously.
scala> Equals[TNil,TypeHolder[TypeHolder[TNil]]#t#t]
<console>:9: error: illegal cyclic reference involving type t
Equals[TNil,TypeHolder[TypeHolder[TNil]]#t#t]
^
Does anyone have any idea what's going on here?
-- Geoff Reedy