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

Antoine Latter aslatter at gmail.com
Sun Oct 2 21:39:22 CEST 2011

On Sun, Oct 2, 2011 at 2:17 PM,  <sdiyazg at sjtu.edu.cn> wrote:
> 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

If I were writing this sort of function, I would simply write:

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

and I would leave it at that. Since your 'expand' doesn't do anything
the three-tuples, I don't see why I would want to call the function
with a three-tuple argument.

But I don't know your full use case.


> 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?
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list