diff options
author | Burak Emir <emir@epfl.ch> | 2006-11-28 16:27:16 +0000 |
---|---|---|
committer | Burak Emir <emir@epfl.ch> | 2006-11-28 16:27:16 +0000 |
commit | 6c468e8927ab8277207b6d21ebe13171509213a8 (patch) | |
tree | 8ecfa442d51147595831a1a5518c256b2a355a63 /src/build/genprod.scala | |
parent | c5e9360725ed37e444b3836185be895bc69e5687 (diff) | |
download | scala-6c468e8927ab8277207b6d21ebe13171509213a8.tar.gz scala-6c468e8927ab8277207b6d21ebe13171509213a8.tar.bz2 scala-6c468e8927ab8277207b6d21ebe13171509213a8.zip |
more fun with positions, and updated doc
Diffstat (limited to 'src/build/genprod.scala')
-rw-r--r-- | src/build/genprod.scala | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/build/genprod.scala b/src/build/genprod.scala index 21c1a8c662..ee5137fc33 100644 --- a/src/build/genprod.scala +++ b/src/build/genprod.scala @@ -225,6 +225,7 @@ object ProductFile { import genprod._ def make(i:Int) = { val __typeArgs__ = if(i==0) Nil else covariantArgs(i).mkString("[",", ","]") + val __refArgs__ = if(i==0) Nil else targs(i).mkString("[",", ","]") <file name={productFilename(i)}> /* __ *\ ** ________ ___ / / ___ Scala API ** @@ -239,6 +240,11 @@ package scala import Predef._ +object {productClassname(i)} {{ + def unapply{__refArgs__}(x:Any): Option[{productClassname(i)}{__refArgs__}] = + if(x.isInstanceOf[{productClassname(i)}{__refArgs__}]) Some(x.asInstanceOf[{productClassname(i)}{__refArgs__}]) else None +}} + /** {productClassname(i)} is a cartesian product of {i} components */ trait {productClassname(i)} {__typeArgs__} extends Product {{ @@ -250,12 +256,13 @@ trait {productClassname(i)} {__typeArgs__} extends Product {{ override def arity = {i} /** - * Returns the n-th projection of this product if 0<n<=arity, otherwise null + * Returns the n-th projection of this product if 0<=n<arity, otherwise null * @param n number of the projection to be returned + * @return same as _(n+1) * @throws IndexOutOfBoundsException */ override def element(n: Int) = n match {{ - {for(val Tuple2(m,j) <- mdefs(i).zip(List.range(1,i+1))) + {for(val Tuple2(m,j) <- mdefs(i).zip(List.range(0,i))) yield "case "+j+" => "+m+"\n "}case _ => throw new IndexOutOfBoundsException(n.toString()) }} |