@@ -53,7 +53,9 @@ package liftable {
53
53
}
54
54
55
55
object Units {
56
- implicit def UnitIsLiftable : Liftable [Unit ] = _=> ' { () }
56
+ implicit def UnitIsLiftable : Liftable [Unit ] = new Liftable [Unit ] {
57
+ def toExpr (x : Unit ): Expr [Unit ] = '()
58
+ }
57
59
}
58
60
59
61
object Lets {
@@ -72,20 +74,26 @@ package liftable {
72
74
73
75
object Tuples {
74
76
75
- implicit def Tuple1IsLiftable [T1 : Liftable ](implicit t1 : Type [T1 ]): Liftable [Tuple1 [T1 ]] = {
76
- case Tuple1 (x1 : T1 ) => ' { Tuple1 [~ t1](~ x1.toExpr) }
77
+ implicit def Tuple1IsLiftable [T1 : Liftable ](implicit t1 : Type [T1 ]): Liftable [Tuple1 [T1 ]] = new Liftable [Tuple1 [T1 ]] {
78
+ def toExpr (x : Tuple1 [T1 ]): Expr [Tuple1 [T1 ]] =
79
+ ' { Tuple1 [~ t1](~ x._1.toExpr) }
77
80
}
78
81
79
- implicit def Tuple2IsLiftable [T1 : Liftable , T2 : Liftable ](implicit t1 : Type [T1 ], t2 : Type [T2 ]): Liftable [(T1 , T2 )] = {
80
- x => ' { Tuple2 [~ t1, ~ t2](~ x._1.toExpr, ~ x._2.toExpr) }
82
+ implicit def Tuple2IsLiftable [T1 : Liftable , T2 : Liftable ](implicit t1 : Type [T1 ], t2 : Type [T2 ]): Liftable [(T1 , T2 )] = new Liftable [(T1 , T2 )] {
83
+ def toExpr (x : (T1 , T2 )): Expr [(T1 , T2 )] =
84
+ ' { Tuple2 [~ t1, ~ t2](~ x._1.toExpr, ~ x._2.toExpr) }
85
+
81
86
}
82
87
83
- implicit def Tuple3IsLiftable [T1 : Liftable , T2 : Liftable , T3 : Liftable ](implicit t1 : Type [T1 ], t2 : Type [T2 ], t3 : Type [T3 ]): Liftable [(T1 , T2 , T3 )] = {
84
- x => ' { Tuple3 [~ t1, ~ t2, ~ t3](~ x._1.toExpr, ~ x._2.toExpr, ~ x._3.toExpr) }
88
+ implicit def Tuple3IsLiftable [T1 : Liftable , T2 : Liftable , T3 : Liftable ](implicit t1 : Type [T1 ], t2 : Type [T2 ], t3 : Type [T3 ]): Liftable [(T1 , T2 , T3 )] = new Liftable [(T1 , T2 , T3 )] {
89
+ def toExpr (x : (T1 , T2 , T3 )): Expr [(T1 , T2 , T3 )] =
90
+ ' { Tuple3 [~ t1, ~ t2, ~ t3](~ x._1.toExpr, ~ x._2.toExpr, ~ x._3.toExpr) }
91
+
85
92
}
86
93
87
- implicit def Tuple4IsLiftable [T1 : Liftable , T2 : Liftable , T3 : Liftable , T4 : Liftable ](implicit t1 : Type [T1 ], t2 : Type [T2 ], t3 : Type [T3 ], t4 : Type [T4 ]): Liftable [(T1 , T2 , T3 , T4 )] = {
88
- x => ' { Tuple4 [~ t1, ~ t2, ~ t3, ~ t4](~ x._1.toExpr, ~ x._2.toExpr, ~ x._3.toExpr, ~ x._4.toExpr) }
94
+ implicit def Tuple4IsLiftable [T1 : Liftable , T2 : Liftable , T3 : Liftable , T4 : Liftable ](implicit t1 : Type [T1 ], t2 : Type [T2 ], t3 : Type [T3 ], t4 : Type [T4 ]): Liftable [(T1 , T2 , T3 , T4 )] = new Liftable [(T1 , T2 , T3 , T4 )] {
95
+ def toExpr (x : (T1 , T2 , T3 , T4 )): Expr [(T1 , T2 , T3 , T4 )] =
96
+ ' { Tuple4 [~ t1, ~ t2, ~ t3, ~ t4](~ x._1.toExpr, ~ x._2.toExpr, ~ x._3.toExpr, ~ x._4.toExpr) }
89
97
}
90
98
91
99
// TODO more tuples
@@ -94,9 +102,11 @@ package liftable {
94
102
95
103
96
104
object Lists {
97
- implicit def ListIsLiftable [T : Liftable ](implicit t : Type [T ]): Liftable [List [T ]] = {
98
- case x :: xs => ' { (~ xs.toExpr).:: [~ t](~ x.toExpr) }
99
- case Nil => ' { Nil : List [~ t] }
105
+ implicit def ListIsLiftable [T : Liftable ](implicit t : Type [T ]): Liftable [List [T ]] = new Liftable [List [T ]] {
106
+ def toExpr (x : List [T ]): Expr [List [T ]] = x match {
107
+ case x :: xs => ' { (~ xs.toExpr).:: [~ t](~ x.toExpr) }
108
+ case Nil => ' { Nil : List [~ t] }
109
+ }
100
110
}
101
111
102
112
implicit class LiftedOps [T : Liftable ](list : Expr [List [T ]])(implicit t : Type [T ]) {
@@ -118,8 +128,8 @@ package liftable {
118
128
}
119
129
120
130
object Arrays {
121
- implicit def ArrayIsLiftable [T : Liftable ](implicit t : Type [T ], ct : Expr [ClassTag [T ]]): Liftable [Array [T ]] = ( arr : Array [T ]) => ' {
122
- new Array [~ t](~ arr.length.toExpr)(~ ct)
131
+ implicit def ArrayIsLiftable [T : Liftable ](implicit t : Type [T ], ct : Expr [ClassTag [T ]]): Liftable [Array [T ]] = new Liftable [ Array [T ]] {
132
+ def toExpr ( arr : Array [ T ]) : Expr [ Array [ T ]] = ' { new Array [~ t](~ arr.length.toExpr)(~ ct) }
123
133
}
124
134
}
125
135
0 commit comments