
From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of phy51km4n
Why does that not work? :
fromTuple (One a) = a fromTuple (Two a b) = (a, b) fromTuple (Three a b c) = (a, b, c) fromTuple (Four a b c d) = (a, b, c, d)
Have you tried it? What are the types of the various cases in fromTuple (you can rename them to get ghci to accept them as separate functions): fromTuple1 :: Tuple a b c d -> a fromTuple1 (One a) = a fromTuple2 :: Tuple a b c d -> ??? fromTuple2 (Two a b) = (a, b)
Why is this correct? :
fromTuple (One a ) = Left (Left a) fromTuple (Two a b ) = Left (Right (a,b)) fromTuple (Three a b c ) = Right (Left (a,b,c)) fromTuple (Four a b c d) = Right (Right (a,b,c,d))
Again, what is the type of just this line? fromTuple (One a ) = Left (Left a) and this line? fromTuple (Two a b ) = Left (Right (a,b)) And if you combine them? fromTuple :: Tuple a b c d -> ??? fromTuple (One a ) = Left (Left a) fromTuple (Two a b ) = Left (Right (a,b)) (You should see that Either's type parameters are progressively filled-in as you add more cases.) Alistair ***************************************************************** Confidentiality Note: The information contained in this message, and any attachments, may contain confidential and/or privileged material. It is intended solely for the person(s) or entity to which it is addressed. Any review, retransmission, dissemination, or taking of any action in reliance upon this information by persons or entities other than the intended recipient(s) is prohibited. If you received this in error, please contact the sender and delete the material from any computer. *****************************************************************