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

Edward Z. Yang ezyang at MIT.EDU
Sun Oct 2 21:26:14 CEST 2011


What are you actually trying to do?  This seems like a rather
unusual function.

Edward

Excerpts from sdiyazg's message of Sun Oct 02 15:17:07 -0400 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