
#14824: automatically select instance -------------------------------------+------------------------------------- Reporter: zaoqi | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Description changed by zaoqi: Old description:
There is {{{#!hs class C a b where m :: [a] -> b instance C X0 X0 instance C X1 X2 instance C X0 X3 }}} FunctionalDependencies can't work.
New description: There is {{{#!hs {-# 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 }}} -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14824#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler