-
Notifications
You must be signed in to change notification settings - Fork 11
/
Comparison.scala
39 lines (39 loc) · 1.06 KB
/
Comparison.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
sealed trait Comparison {
type gt <: Bool
type ge <: Bool
type eq <: Bool
type le <: Bool
type lt <: Bool
type Match[IfLT <: Up, IfEQ <: Up, IfGT <: Up, Up] <: Up
}
sealed trait GT extends Comparison {
type Match[IfLT <: Up, IfEQ <: Up, IfGT <: Up, Up] = IfGT
type eq = False
type gt = True
type lt = False
type le = False
type ge = True
}
sealed trait LT extends Comparison {
type Match[IfLT <: Up, IfEQ <: Up, IfGT <: Up, Up] = IfLT
type eq = False
type gt = False
type lt = True
type le = True
type ge = False
}
sealed trait EQ extends Comparison {
type Match[IfLT <: Up, IfEQ <: Up, IfGT <: Up, Up] = IfEQ
type eq = True
type gt = False
type lt = False
type le = True
type ge = True
}
object Comparison {
def show[C <: Comparison](implicit rep: ComparisonRep[C]): String = rep.value
implicit def eqToRep: ComparisonRep[EQ] = new ComparisonRep[EQ]("eq")
implicit def ltToRep: ComparisonRep[LT] = new ComparisonRep[LT]("lt")
implicit def gtToRep: ComparisonRep[GT] = new ComparisonRep[GT]("gt")
final class ComparisonRep[+C <: Comparison](val value: String)
}