[Haskell-cafe] Is it possible to represent such polymorphism?

Du Xi sdiyazg at sjtu.edu.cn
Sun Oct 2 15:04:10 CEST 2011


--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





More information about the Haskell-Cafe mailing list