Is there a name for the following concept? Can you point me to any references on it?<br><br>Suppose I have the following two functions ...<br><br>> swap1 :: (Int, Char) -> (Char, Int)<br>> swap2 :: (Char, Int) -> (Int, Char)<br>
<br>... and, for some reason, I think I can unify these into a single function. I think, hmm, given that the structure is that same, let's do a first pass:<br><br>> swap? :: (a, b) -> (c, d)<br><br>But then I go back to the input types to confirm that this will work, and, alas, it will not, because there are similarities that I missed. This is way too general. I need to ensure that what's an Int stays an Int and likewise for Char.<br>
<br>> swap! :: (a, b) -> (b, a)<br><br>And now I have found a type that is more general than swap1 and swap2 and yet not so general that the shared constraints are left out. This seems somewhat analogous to the least common multiple.<br>
<br>Another example is the following:<br><br>> showFloat :: Float -> String<br>> showBool :: Bool -> String<br><br>We could say the more general type is ...<br><br>> show? :: a -> String<br><br>... but then we lose the implied constraint that we must know something about 'a' to produce a string. So, we add back such some such constraint:<br>
<br>> show! :: (Show a) => a -> String<br><br>Of course, with all of this, it may not be clear what to do about the definitions of the functions, but I'm curious if there's a name for the concept from a type perspective.<br>
<br>Thanks,<br>Sean<br>