[Haskell-cafe] "Least common supertype"?

Nicolas Pouillard nicolas.pouillard at gmail.com
Wed Nov 11 15:53:26 EST 2009

Excerpts from Sean Leather's message of Wed Nov 11 21:24:43 +0100 2009:
> Is there a name for the following concept? Can you point me to any
> references on it?
> Suppose I have the following two functions ...
> > swap1 :: (Int, Char) -> (Char, Int)
> > swap2 :: (Char, Int) -> (Int, Char)
> ... 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:
> > swap? :: (a, b) -> (c, d)
> 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.
> > swap! :: (a, b) -> (b, a)

In the literature this is also called anti-unification (anti-unifier). These
techniques had been used for formalising some overloading systems.

Nicolas Pouillard

More information about the Haskell-Cafe mailing list