Haskell Typeclass for Tuples -
i playing around typeclasses , made this:
class firstable f fst :: f -> class secondable f snd :: f -> i tried add implementation (,) , realized do:
instance secondable ((,) a) snd (x,y) = y i'm pretty sure works because secondable should have kind (* -> *) ((,) a) has type, however, don't know how implement firstable ((,) * a) * bound variable, in interpretation trying equivalent of:
instance firstable (flip (,) a) ... is there way in haskell? preferably without extensions?
thanks!
a version worse parametricity guarantees can had mptcs , fundeps or typefamilies.
type family fst p type instance fst (a,b) = type instance fst (a,b,c) = ...
class first p fst :: p -> fst p instance fst (a,b) fst (a,_) = instance fst (a,b,c) fst (a,_,_) = ...
but ultimately, you'll need use extensions.
Comments
Post a Comment