Skip to content

Commit 911d4f1

Browse files
committed
New test case
A simplified test case which adopts several improvements from Miles Sabin's branch. Compared to typeclass-derivation2c.scala: - The alternatives and numberOfCases methods are gone - All compiler-generated info is in the companion objects; no additional classes are generated. - The derivation code largely uses the type traversals of the previous schemes instead of simple counting, as was the case in typeclass-derivation2c.scala. - Generic has been renamed to Mirror, following a suggestion by Miles (but now all mirrors are static) The key insight is that we do not need a mapping from the sum type to its alternatives except knowing what the alternative types are. Once we have an alternative type, we can use an implicit match to retrieve the mirror for that alternative.
1 parent fb6667b commit 911d4f1

File tree

2 files changed

+463
-0
lines changed

2 files changed

+463
-0
lines changed
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
ListBuffer(0, 11, 0, 22, 0, 33, 1)
2+
Cons(11,Cons(22,Cons(33,Nil)))
3+
ListBuffer(0, 0, 11, 0, 22, 0, 33, 1, 0, 0, 11, 0, 22, 1, 1)
4+
Cons(Cons(11,Cons(22,Cons(33,Nil))),Cons(Cons(11,Cons(22,Nil)),Nil))
5+
ListBuffer(1, 2)
6+
Pair(1,2)
7+
Cons(hd = 11, tl = Cons(hd = 22, tl = Cons(hd = 33, tl = Nil())))
8+
Cons(hd = Cons(hd = 11, tl = Cons(hd = 22, tl = Cons(hd = 33, tl = Nil()))), tl = Cons(hd = Cons(hd = 11, tl = Cons(hd = 22, tl = Nil())), tl = Nil()))
9+
Cons(hd = Left(x = 1), tl = Cons(hd = Right(x = Pair(x = 2, y = 3)), tl = Nil()))
10+
Cons(hd = Left(x = 1), tl = Cons(hd = Right(x = Pair(x = 2, y = 3)), tl = Nil()))

0 commit comments

Comments
 (0)