How can I handle operations over many different types in my DSL?
Suppose Haskell is to be used to implement an interpreter for a domain specific language. The DSL has a large number of type, represented as data constructors, and a large number of binary expressions. A naive first attempt would be a type class BinaryOps encapsulating all binary operations over MyType in the DSL: data MyType = A String | B Integer | C Bool | D Double {- | E .. Z -} class BinaryOps a where f :: a -> a -> a g :: a -> a -> a h :: a -> a -> a j :: a -> a -> a {- many more binary ops -} instance BinaryOps MyType where f (A s1) (A s2) = {- Haskell expression on s1 and s2 -} f (A s1