I was trying to port the following Haskell code:
data Name a = Fn String !Integer | Bn !Integer !Integer deriving (Eq, Ord) data AnyName where AnyName :: Typeable a => Name a -> AnyName instance Eq AnyName where (AnyName n1) == (AnyName n2) = case gcast n2 of Just n2' -> n1 == n2' Nothing -> False
With the help of
Data.Exists module, I managed to get this far:
import Data.Exists data Name a = Fn String Int | Bn Int Int derive instance eqName :: Eq (Name a) derive instance ordName :: Ord (Name a) data AnyName = AnyName (Exists Name) instance eqAnyName :: Eq AnyName where eq (AnyName x) (AnyName y) = undefined
and got stuck.
What the original Haskell
Eq does is comparing the type of existentially hidden phantom types first and only comparing the actual values if types are the same.
Because the phantom type is existentially hidden, in Purescript I have to mimic that with
Data.Exists. But then again, how can I compare the types when implementing
Eq instance? Even if I get pass that, how to compare the actual values?
unsafeCoerce lhs == rhs simply throws
How would you write the
Eq instance for
AnyName? Is it possible at all?
The same goes for the
Ord instance. I want to store
AnyName in a