I would start with a single-parameter type class with two associated
type families for
class Transform t where
type TransIn t
type TransOut t
trans :: t -> TransIn t -> TransOut t
Now you need six instances for the six equations for
TypeOut. Here is the first one.
instance Transform (R PA (S a)) where
type TransIn (R PA (S a)) = a
type TransOut (R PA (S a)) = Box (R PA (S a)) a
trans t a = error "implement me!"
Note that the definitions for
TransOut are literally the equations from the question.