
How about this:
class (a x, b x) => (a `And` b) x instance (a x, b x) => (a `And` b) x infixr 3 `And`
data S c e where SC :: c d => d -> e -> S c e
foo :: S (Show `And` Read `And` Num) Int foo = SC (5.0 :: Double) (6 :: Int)
Richard
On Jun 19, 2015, at 4:13 PM, Leza Morais Lutonda
On 06/19/2015 08:44 AM, Sean Leather wrote:
Note this won't work for a Num instance mentioned earlier because the existentially quantified d types in two SC values are not provably the same type. In other words, you can't write
instance Num e => Show (S Num e) where SC x1 y1 + SC x2 y2 = SC (x1 + x2) (y1 + y2)
because x1 and x2 can have different types. Another issue is: what if I want to constraint the type `e` to more classes and make `d` to have the same constrains? I have to re-declare the `S` data type like?:
data S c1 c2 ... cN e where SC :: (c1 d, c2 d, ..., cN d) -> d -> e -> S c1 c2 ... cN e
Does anyone ever needed such a feature? -- Leza Morais Lutonda, Lemol-C http://lemol.github.io 50 Aniversario de la Cujae. Inaugurada por Fidel el 2 de diciembre de 1964 http://cujae.edu.cu
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe