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

Tom Murphy amindfv at gmail.com
Sun Oct 2 22:22:49 CEST 2011

Assuming that z :: Int, you can declare an algebraic datatype
data TwoOrThree a b = Three (a, b, Int)
                    | Two (a, b)
   deriving(Show, Eq) -- so you can experiment

And then define expand as

expand :: TwoOrThree a b -> (a, b, Int)
expand (Three tuple) = tuple
expand (Two (a, b)) = (a, b, 1)

Tom (amindfv)
On Oct 2, 2011 6:04 AM, "Du Xi" <sdiyazg at sjtu.edu.cn> wrote:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20111002/cd90bb90/attachment.htm>

More information about the Haskell-Cafe mailing list