automatically select instance
There is
{-# LANGUAGE OverlappingInstances, MultiParamTypeClasses #-}
data X0 = X0 deriving Show
data X1 = X1 deriving Show
data X2 = X2 deriving Show
data X3 = X3 deriving Show
class C a b where m :: [a] -> b
instance C X0 X0 where m _ = X0
instance C X1 X2 where m _ = X2
instance C X0 X3 where m _ = X3
X0 X1 X2 X3 is 4 types in real program. FunctionalDependencies can't work.
*Main> m [X1]
<interactive>:6:1: error:
• Ambiguous type variable ‘a0’ arising from a use of ‘print’
prevents the constraint ‘(Show a0)’ from being solved.
Probable fix: use a type annotation to specify what ‘a0’ should be.
These potential instances exist:
instance Show Ordering -- Defined in ‘GHC.Show’
instance Show Integer -- Defined in ‘GHC.Show’
instance [overlap ok] [safe] Show X0 -- Defined at a.hs:2:23
...plus 26 others
...plus 11 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In a stmt of an interactive GHCi command: print it