Skip to content

Commit 8d1c73b

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

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-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: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
-- | Instances should not be defined in libraries.
32+
class TypeEqualsBool a b (o :: Boolean) | a b -> o
33+
34+
instance reflTypeEqualsBool :: TypeEqualsBool a a True
35+
else instance notTypeEqualsBool :: TypeEqualsBool a b False

0 commit comments

Comments
 (0)