{-# LANGUAGE FlexibleInstances, TypeFamilies, IncoherentInstances #-} class Foo a where foo :: a instance a ~ Int => Foo (String -> a) where foo = length instance a ~ String => Foo a where foo = "world" main = do print $ foo "hello" print $ foo