« Return to Thread: compiler weirdness with crazy types

compiler weirdness with crazy types

by Matt Hellige :: Rate this Message:

Reply to Author | View in Thread

Sorry for the vague subject, I'm not sure how else to describe this.

This is based on some thinking about the following blog post:
  http://michid.wordpress.com/2008/07/30/meta-programming-with-scala-part-ii-multiplication/#comment-69

Consider:
  object Church {
    abstract class Zero
    abstract class Succ[T]

    type _0[s[_], z] = z
    type _1[s[_], z] = s[z]
    type _2[s[_], z] = s[s[z]]
    type _3[s[_], z] = s[s[s[z]]]
    type _4[s[_], z] = s[s[s[s[z]]]]

    trait apply1[t[_[_],_],u[_]] {
      type It[a] = t[u,a]
    }

    type mul[m[s[_], z], n[s[_], z], s[_], z] = m[apply1[n,s]#It, z]
    type x[m[s[_], z], n[s[_], z]] = mul[m, n, Succ, Zero]

    type three = _3 x _1
    //type four = _2 x _2
    type six = _2 x _3
    type eight = _4 x _2
  }

This code compiles fine. We can even use the defined types! But if we
uncomment the definition of "four":
  type four = _2 x _2
then we get the following:
  church2.scala:19: error: illegal cyclic reference involving type _2
    type four = _2 x _2
         ^
  church2.scala:20: error: illegal cyclic reference involving type x
    type six = _2 x _3
                  ^
  church2.scala:21: error: illegal cyclic reference involving type x
    type eight = _4 x _2
                    ^
  three errors found

Notice that even the previously working definitions are now broken?
Why? What gives??

(This is with the current nightly build.)

Thanks...
Matt

--
Matt Hellige / matt@...
http://matt.immute.net

 « Return to Thread: compiler weirdness with crazy types