Suppose I have a type:

data A a b = A a String b Int

and classes

class C1 t where
        c1 :: t a -> (a, Int)

class C2 t where
        c2 :: t a -> (a, String)

 (the example is not practical, but shows the case).
Now, whilst I can say:

instance C1 (A a) where
        c1 (A a s b i) = (b, i)

I cannot say:
instance C2 (A ...) where
        c2 (A a s b i) = (a, s)

where ... is the missing syntax - for saying that I want to generalize over the
first type variable in A, not the second one as in instance C1. Wouldn't it
be nice to be able to say, in the place of ..., something like A _ a? Or
more generally, to develop some syntax for types like A, to create from
A not only:

type B = A (Int, Int)  --      A (Int, Int) String b Int    

but also:

type B1 = ...           --      A a String (Int, Int) Int

where again ... is the missing syntax (A _ (Int, Int)? ).
If that would be possible, I could ask for even more happiness - to be able
to name the order of holes left in a definition, so that 
(pseudo-syntax):

data A a b c = A a b c

type C = A _2 _1 Int          -- C String Char = A Char String Int
                              -- C String = A _1 String Int
                              -- C = A _2 _1 Int

The "normal" definitions can be translated to a new syntax:

type D = A Int               -- D = A Int _1 _2

It all comes to lambda-expressions on types - 

type C = \b a -> A a b Int

instance C2 (\a -> A a b) where
instance C1 (\b -> A a b) where

The rule of translation from normal syntax is obvious - if we have
data A a1 ... an = A a1 ... an, then 

A a1 translates to (\a2 ... an -> A a1 ... an)
A a1 a2 translates to (\a3 ... an -> A a1 ... an)

and so on.

It's just a couple of thoughts, perhaps impossible to implement or having
some hidden flaws - I do not know. But it really would be helpful sometimes - 
when dealing with very general types and operations on them.

Khaliff TM                                   [EMAIL PROTECTED]


Reply via email to