@@ -44,9 +44,7 @@ object AlgebraBoilerplate {
4444 val synVals = (0 until arity).map(n => s " a $n" )
4545 val `A..N` = synTypes.mkString(" , " )
4646 val `a..n` = synVals.mkString(" , " )
47- val `_.._` = Seq .fill(arity)(" _" ).mkString(" , " )
4847 val `(A..N)` = if (arity == 1 ) " Tuple1[A0]" else synTypes.mkString(" (" , " , " , " )" )
49- val `(_.._)` = if (arity == 1 ) " Tuple1[_]" else Seq .fill(arity)(" _" ).mkString(" (" , " , " , " )" )
5048 val `(a..n)` = if (arity == 1 ) " Tuple1(a)" else synVals.mkString(" (" , " , " , " )" )
5149 }
5250
@@ -86,32 +84,32 @@ object AlgebraBoilerplate {
8684 import tv ._
8785
8886 def constraints (constraint : String ) =
89- synTypes.map(tpe => s " ${ tpe} : ${ constraint} [ ${ tpe} ] " ).mkString(" , " )
87+ synTypes.map(tpe => s " $tpe: $constraint[ $ tpe] " ).mkString(" , " )
9088
9189 def tuple (results : TraversableOnce [String ]) = {
9290 val resultsVec = results.toVector
9391 val a = synTypes.size
9492 val r = s " ${0 .until(a).map(i => resultsVec(i)).mkString(" , " )}"
9593 if (a == 1 ) " Tuple1(" ++ r ++ " )"
96- else s " ( ${r} ) "
94+ else s " ( $r ) "
9795 }
9896
9997 def binMethod (name : String ) =
10098 synTypes.zipWithIndex.iterator.map { case (tpe, i) =>
10199 val j = i + 1
102- s " ${ tpe} . ${ name} (x._ ${j} , y._ ${j} ) "
100+ s " $tpe. $ name(x._ $j , y._ $j ) "
103101 }
104102
105103 def binTuple (name : String ) =
106104 tuple(binMethod(name))
107105
108106 def unaryTuple (name : String ) = {
109- val m = synTypes.zipWithIndex.map { case (tpe, i) => s " ${ tpe} . ${ name} (x._ ${i + 1 }) " }
107+ val m = synTypes.zipWithIndex.map { case (tpe, i) => s " $tpe. $ name(x._ ${i + 1 }) " }
110108 tuple(m)
111109 }
112110
113111 def nullaryTuple (name : String ) = {
114- val m = synTypes.map(tpe => s " ${ tpe} . ${ name} " )
112+ val m = synTypes.map(tpe => s " $tpe. $ name" )
115113 tuple(m)
116114 }
117115
@@ -124,36 +122,36 @@ object AlgebraBoilerplate {
124122 |trait TupleInstances extends cats.kernel.instances.TupleInstances {
125123 -
126124 - implicit def tuple ${arity}Rig[ ${`A..N`}](implicit ${constraints(" Rig" )}): Rig[ ${`(A..N)`}] =
127- - new Rig[ ${`(A..N)`} ] {
128- - def one: ${`(A..N)`} = ${ nullaryTuple(" one " )}
129- - def plus(x: ${`(A..N)`} , y: ${`(A..N)`} ): ${`(A..N)`} = ${binTuple( " plus " )}
130- - def times(x: ${`(A..N)`} , y: ${`(A..N)`} ): ${`(A..N)`} = ${binTuple(" times " )}
131- - def zero: ${`(A..N)`} = ${nullaryTuple( " zero " )}
132- - }
125+ - Rig.instance(
126+ - ${ nullaryTuple(" zero " )},
127+ - ${nullaryTuple( " one " )},
128+ - (x , y) => ${binTuple(" plus " )},
129+ - (x, y) => ${binTuple( " times " )}
130+ - )
133131 -
134132 - implicit def tuple ${arity}Ring[ ${`A..N`}](implicit ${constraints(" Ring" )}): Ring[ ${`(A..N)`}] =
135- - new Ring[ ${`(A..N)`} ] {
136- - def one: ${`(A..N)`} = ${ nullaryTuple(" one " )}
137- - def plus(x: ${`(A..N)`} , y: ${`(A..N)`} ): ${`(A..N)`} = ${binTuple( " plus " )}
138- - def times(x: ${`(A..N)`} , y: ${`(A..N)`} ): ${`(A..N)`} = ${binTuple( " times " )}
139- - def zero: ${`(A..N)`} = ${nullaryTuple( " zero " )}
140- - def negate(x: ${`(A..N)`} ): ${`(A..N)`} = ${unaryTuple( " negate " )}
141- - }
133+ - Ring.instance(
134+ - ${ nullaryTuple(" zero " )},
135+ - ${nullaryTuple( " one " )},
136+ - x => ${unaryTuple( " negate " )},
137+ - (x, y) => ${binTuple( " plus " )},
138+ - (x, y) => ${binTuple( " times " )}
139+ - )
142140 -
143141 - implicit def tuple ${arity}Rng[ ${`A..N`}](implicit ${constraints(" Rng" )}): Rng[ ${`(A..N)`}] =
144- - new Rng[ ${`(A..N)`} ] {
145- - def plus(x: ${`(A..N)`} , y: ${`(A..N)`} ): ${`(A..N)`} = ${binTuple( " plus " )}
146- - def times(x: ${`(A..N)`} , y: ${`(A..N)`} ): ${`(A..N)`} = ${binTuple( " times " )}
147- - def zero: ${`(A..N)`} = ${nullaryTuple( " zero " )}
148- - def negate(x: ${`(A..N)`} ): ${`(A..N)`} = ${unaryTuple( " negate " )}
149- - }
142+ - Rng.instance(
143+ - ${nullaryTuple( " zero " )},
144+ - x => ${unaryTuple( " negate " )},
145+ - (x, y) => ${binTuple( " plus " )},
146+ - (x, y) => ${binTuple( " times " )}
147+ - )
150148 -
151149 - implicit def tuple ${arity}Semiring[ ${`A..N`}](implicit ${constraints(" Semiring" )}): Semiring[ ${`(A..N)`}] =
152- - new Semiring[ ${`(A..N)`} ] {
153- - def plus(x: ${`(A..N)`} , y: ${`(A..N)`} ): ${`(A..N)`} = ${binTuple( " plus " )}
154- - def times(x: ${`(A..N)`} , y: ${`(A..N)`} ): ${`(A..N)`} = ${binTuple(" times " )}
155- - def zero: ${`(A..N)`} = ${nullaryTuple( " zero " )}
156- - }
150+ - Semiring.instance(
151+ - ${nullaryTuple( " zero " )},
152+ - (x , y) => ${binTuple(" plus " )},
153+ - (x, y) => ${binTuple( " times " )}
154+ - )
157155 |}
158156 """
159157 }
0 commit comments