I built a type Sup
that embeds a value of another type t
using constructor subtyping.
data Sup t = ...
| Sub t
deriving Eq
Because the part omitted from Sup
contains lots of constructors, none of which use t
, I want to derive Eq (Sup t)
rather than give a manual instance.
A type constraint Eq t
is now in place on the instance of (==)
for Sup t
:
(==) :: Eq t => Sup t -> Sup t -> Bool
The predicate isSub :: Sup t -> Bool
is defined as follows:
isSub :: Sup t -> Bool
isSub (Sub _) = True
isSub _ = False
With the help of this predicate I would like to define the following operator:
supEq :: Sup t -> Sup t -> Bool
supEq x y = not (isSub x) && not (isSub y) && x == y
The above definition is not accepted by GHC, as the type-constraint Eq t
is missing. However, thanks to lazy evaluation, I know that equality between values of type t
is never actually used.
Is there a way that I can force GHC to ignore the missing type-constraint?
Alternatively, is there a way I could have defined Sup
or supEq
to get the desired result: a definition of supEq
without having to propagate a redundant type constraint wherever supEq
is used and without having to give a manual instance for Eq (Sup t)
.
supEq
to judge two values of the formSup a
always as unequal, evensupEq (Sub 1) (Sub 1) ≡ False
? Might be helpful to clearly state this in the question. – leftaroundabout