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

sdiyazg at sjtu.edu.cn sdiyazg at sjtu.edu.cn
Sun Oct 2 21:17:07 CEST 2011


Finally I got what I meant:


class ExpandTuple t where
	type Result t
	expand :: t->Result t

instance (Integral a)=>ExpandTuple (a,a) where
	type Result (a,a) = (a,a,a)
	expand (x,y) = (x,y,1)

instance (Integral a)=>ExpandTuple (a,a,a) where
	type Result (a,a,a) = (a,a,a)
	expand = id

But it's so verbose (even more so than similar C++ template code I  
guess), introduces an additional name (the typeclass) into the current  
scope, and requires 2 extensions: TypeFamilies and  
FlexibleInstances.Is there a cleaner way to do this?




More information about the Haskell-Cafe mailing list