2-tuple and 3-tuple are not the same type.
So to do this you must use typeclasses.
Plus you have to deal with the type parameters

class To3Tuple a where
   expand :: a -> (Int, Int, Int)

instance To3Tuple (Int, Int, Int) where
   expand = id

instance To3Tuple (Int, Int) where
   expand (x,y) = (x,y,1)


Here I had to force my tuples to be tuples of integers.
It's more complicated if you want polymorphism.


2011/10/2 Du Xi <sdiyazg@sjtu.edu.cn>
--I tried to write such polymorphic function:

expand (x,y,z) = (x,y,z)
expand (x,y) = (x,y,1)

--And it didn't compile. Then I added a type signature:

expand::a->b
expand (x,y,z) = (x,y,z)
expand (x,y) = (x,y,1)

--It still didn't compile. I think the reason is that the following is disallowed:

f::a->b
f x = x

--Is it possible to get around this and write the "expand" function? Of course, x and y may be of different types



_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe