Skip to content

Commit 6763ee3

Browse files
committed
TypeEqualsBool class can assert type inequality.
Depends on Instance Chains.
1 parent 979f06a commit 6763ee3

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

bower.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
],
1818
"dependencies": {
1919
"purescript-proxy": "^2.0.0",
20-
"purescript-symbols": "^3.0.0",
21-
"purescript-type-equality": "^2.0.0"
20+
"purescript-symbols": "^3.0.0"
2221
}
2322
}

src/Type/Equality.purs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
module Type.Equality
2+
( class TypeEquals
3+
, to
4+
, from
5+
, class TypeEqualsBool
6+
) where
7+
8+
import Type.Data.Boolean (kind Boolean, True, False)
9+
10+
-- | This type class asserts that types `a` and `b`
11+
-- | are equal.
12+
-- |
13+
-- | The functional dependencies and the single
14+
-- | instance below will force the two type arguments
15+
-- | to unify when either one is known.
16+
-- |
17+
-- | Note: any instance will necessarily overlap with
18+
-- | `refl` below, so instances of this class should
19+
-- | not be defined in libraries.
20+
class TypeEquals a b | a -> b, b -> a where
21+
to :: a -> b
22+
from :: b -> a
23+
24+
instance refl :: TypeEquals a a where
25+
to a = a
26+
from a = a
27+
28+
-- | This type class asserts that types `a` and `b`
29+
-- | are or are not equal, depending on the type of `o`.
30+
-- |
31+
-- | `o` will be either `True`, if `a` is `b`,
32+
-- | or `False` otherwise.
33+
-- |
34+
-- | When `o` is specified to be `True`/`False` then this type class
35+
-- | acts as an assertion that `a` and `b` are equal/not equal, respectively.
36+
-- |
37+
-- | Instances should not be defined in libraries.
38+
class TypeEqualsBool a b (o :: Boolean) | a b -> o
39+
40+
instance reflTypeEqualsBool :: TypeEqualsBool a a True
41+
else instance notTypeEqualsBool :: TypeEqualsBool a b False

0 commit comments

Comments
 (0)