From 6763ee3304ec28f152283933ab617bf7f95f58fa Mon Sep 17 00:00:00 2001 From: Matthew Leon Date: Thu, 25 Jan 2018 20:58:56 -0500 Subject: [PATCH] TypeEqualsBool class can assert type inequality. Depends on Instance Chains. --- bower.json | 3 +-- src/Type/Equality.purs | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 src/Type/Equality.purs diff --git a/bower.json b/bower.json index f737bf1..e60e1b2 100644 --- a/bower.json +++ b/bower.json @@ -17,7 +17,6 @@ ], "dependencies": { "purescript-proxy": "^2.0.0", - "purescript-symbols": "^3.0.0", - "purescript-type-equality": "^2.0.0" + "purescript-symbols": "^3.0.0" } } diff --git a/src/Type/Equality.purs b/src/Type/Equality.purs new file mode 100644 index 0000000..fbf6a89 --- /dev/null +++ b/src/Type/Equality.purs @@ -0,0 +1,41 @@ +module Type.Equality + ( class TypeEquals + , to + , from + , class TypeEqualsBool + ) where + +import Type.Data.Boolean (kind Boolean, True, False) + +-- | This type class asserts that types `a` and `b` +-- | are equal. +-- | +-- | The functional dependencies and the single +-- | instance below will force the two type arguments +-- | to unify when either one is known. +-- | +-- | Note: any instance will necessarily overlap with +-- | `refl` below, so instances of this class should +-- | not be defined in libraries. +class TypeEquals a b | a -> b, b -> a where + to :: a -> b + from :: b -> a + +instance refl :: TypeEquals a a where + to a = a + from a = a + +-- | This type class asserts that types `a` and `b` +-- | are or are not equal, depending on the type of `o`. +-- | +-- | `o` will be either `True`, if `a` is `b`, +-- | or `False` otherwise. +-- | +-- | When `o` is specified to be `True`/`False` then this type class +-- | acts as an assertion that `a` and `b` are equal/not equal, respectively. +-- | +-- | Instances should not be defined in libraries. +class TypeEqualsBool a b (o :: Boolean) | a b -> o + +instance reflTypeEqualsBool :: TypeEqualsBool a a True +else instance notTypeEqualsBool :: TypeEqualsBool a b False