In Haskell, it's easy to write functions that act or return tuples of things, for example. splitAt foreplay function:
splitAt :: Int -> [a] -> ([a], [a])
but is there a simple, convenient way to write functions that act or lead to a totality of things? For example. function that returns an int or double. As a specific example, suppose I want to write a function
MyDivision :: Int -> Int -> (Int + Double)
where + is my cotupling character, so MyDivision xy returns x / y as Int if division leads to an integer, but like Double if division does not lead to an integer.
So far it seems that I have two options: declare a new data type
data IntOrDouble = AnInt Int | ADouble Double
or use
Either Int Double
where the first alternative requires a lot of typing and thinking about names, and the second alternative quickly becomes messy when you have large nodes and get types similar to
Either (Either a (Either bc)) (Either (Either df) g)
Now, if I had a cotuple type, say
a + b + c + d
I would like to be able to create functions
f :: (a + b + c + d) -> e g :: (a + b + c + d) -> (e + f + g + h)
just delivering functions
f1 :: a -> e, f2 :: b -> e, f3 :: c -> e, f4 :: d -> e g1 :: a -> e, g2 :: b -> f, g3 :: c -> g, g4 :: d -> h
and installation
f = f1 + f2 + f3 + f4 g = g1 <+> g2 <+> g3 <+> g4
or something similar.
Is it possible?