Hello,
Could somebody explain the situation with the nested types in the
Haskell instances ?
Consider an example:
------------------------------------------------------------------
data D a = D (a,Int)
class Eq a => C a where opC :: a -> a
instance (C a, C b) => C (D (a,b))
where
opC (D ((x,y),k)) = D ((f x, f y), k+1) where f = ...
------------------------------------------------------------------
This means that the programmer whants to define the C instance for
D c for the case when c = (a,b) and is able to do this only by
using the projections of the elements of c.
But Haskell does not allow this nested constructs C (D (a,b)) in
the instance declaration.
Question 1. What might be the way out ?
We might think of modelling direct product by the class with pro-
jections
class Eq a => Pair a where p1,p2 :: a -> a
pair :: a -> a -> a
where pi serve as the projections, so a is viewed as a direct
product of the subsets pi(a):
a = p1(a) x p2(a).
But this would hardly work, for formally we still are inside the
same type `a' with all its instances, say, the algebraic instances
for (Integer,Integer).
And applying (p1 (2,3)) we hope to expresses (2,0) and refer to
the instances for Integer only - which are quite different.
Question 2.
If there is no reasonable way out, then could new Haskell language
allow this nested constructs in instances ?
Thank you.
Sergei Mechveliani [EMAIL PROTECTED]