|
1 | 1 | package org.cvogt.scala.constraint
|
2 | 2 | import scala.annotation.implicitNotFound
|
3 | 3 |
|
4 |
| -/** Verifies that From is NOT a subtype of To */ |
5 |
| -@implicitNotFound(msg = |
6 |
| -""" |
7 |
| -Cannot prove that |
8 |
| -${From} |
9 |
| -is not a subtype of |
10 |
| -${To}""" |
11 |
| -) |
12 |
| -trait !<:[From, To] |
13 |
| -object !<:{ |
14 |
| - /** implicit that verifies !<: */ |
15 |
| - implicit def conforms_!<:[A,B](implicit ev: Allow_!<:[A, B]): A !<: B = null |
| 4 | +import boolean._ |
| 5 | + |
| 6 | +/** |
| 7 | +type-level constraints for subtyping and type identity checks. |
| 8 | +*/ |
| 9 | +object `package`{ |
| 10 | + @implicitNotFound(msg = "Cannot prove ${Left} =:= ${Right}") |
| 11 | + type =:=[Left,Right] = scala.Predef.=:=[Left,Right] |
| 12 | + @implicitNotFound(msg = "Cannot prove ${Left} <:< ${Right}") |
| 13 | + type <:<[Left,Right] = scala.Predef.<:<[Left,Right] |
| 14 | + |
| 15 | + @implicitNotFound(msg = """Cannot prove ${Left} !<:< ${Right}""") |
| 16 | + type !<:<[Left,Right] = ![<:<[Left,Right]] |
| 17 | + @implicitNotFound(msg = """Cannot prove ${Left} !=:= ${Right}""") |
| 18 | + type !=:=[Left,Right] = ![=:=[Left,Right]] |
| 19 | + |
| 20 | + |
| 21 | + @implicitNotFound(msg = """Cannot prove ${Left} >:> ${Right}""") |
| 22 | + type >:>[Right,Left] = <:<[Left,Right] |
| 23 | + @implicitNotFound(msg = """Cannot prove ${Left} !>:> ${Right}""") |
| 24 | + type !>:>[Right,Left] = !<:<[Left,Right] |
16 | 25 | }
|
17 |
| -/** Helper class for !<: */ |
18 |
| -trait Allow_!<:[From, To] |
19 |
| -object Allow_!<:{ |
20 |
| - /** Allow any two types fo !<: */ |
21 |
| - implicit def allow_!<:[From, To]: Allow_!<:[From, To] = null |
22 |
| - /** Creates an ambigious implicit for From <: To to prevent that case. */ |
23 |
| - implicit def disallow_!<:[From, To](implicit ev: From <:< To): Allow_!<:[From, To] = null |
| 26 | +/* |
| 27 | +/** Proves that Left is NOT a subtype of ${Right} */ |
| 28 | +@implicitNotFound(msg = "Cannot prove ${Left} !<:< ${Right}") |
| 29 | +final class !<:<[Left, ${Right}] |
| 30 | +object !<:<{ |
| 31 | + implicit def prove[Left,Right](implicit ev: ![Left <:< ${Right}]) = new !<:<[Left,Right] |
24 | 32 | }
|
25 | 33 |
|
26 |
| -/** Verifies that From is not identical to To */ |
27 |
| -@implicitNotFound(msg = |
28 |
| -""" |
29 |
| -Cannot prove that |
30 |
| -${From} |
31 |
| -is not identical to |
32 |
| -${To}""" |
33 |
| -) |
34 |
| -trait !=:=[From, To] |
| 34 | +/** Proves that Left is NOT identical to ${Right} */ |
| 35 | +@implicitNotFound(msg = "Cannot prove ${Left} !=:= ${Right}") |
| 36 | +final class !=:=[Left, ${Right}] |
35 | 37 | object !=:={
|
36 |
| - /** implicit that verifies !=:= */ |
37 |
| - implicit def conforms_!=:=[A,B](implicit ev: Allow_!=:=[A, B]): A !=:= B = null |
38 |
| -} |
39 |
| -/** Helper class for !=:= */ |
40 |
| -trait Allow_!=:=[From, To] |
41 |
| -object Allow_!=:={ |
42 |
| - /** Allow any two types fo !=:= */ |
43 |
| - implicit def allow_!=:=[From, To]: Allow_!=:=[From, To] = null |
44 |
| - /** Creates an ambigious implicit for From =:= To to prevent that case. */ |
45 |
| - implicit def disallow_!=:=[From, To](implicit ev: From =:= To): Allow_!=:=[From, To] = null |
| 38 | + implicit def prove[Left,Right](implicit ev: ![Left =:= ${Right}]) = new !=:=[Left,Right] |
46 | 39 | }
|
| 40 | +*/ |
0 commit comments