I was playing around with typeclasses and made this:
class Firstable f where
fst :: f a -> a
class Secondable f where
snd :: f a -> a
I then tried to add an implementation for (,) and realized that I could do:
instance Secondable ((,) a) where
snd (x,y) = y
I’m pretty sure this works because Secondable should have kind (* -> *) where ((,) a) has that type, however, I don’t know how to implement Firstable for ((,) * a) where * is the bound variable, In my interpretation I am trying to do the equivalent of:
instance Firstable (flip (,) a) where ...
Is there a way to do this in Haskell? Preferably without extensions?
A version with worse parametricity guarantees can be had with MPTCS and Fundeps or with TypeFamilies.
…
…
but ultimately, you’ll need to use some extensions.