
Who knows, please, why does there happen, now and then, the effects of the following kind? The ghc-6-4-branch-June-15-2005 compiler cannot resolve the Show instances in the following program (using overlapping and `undecidable' instances): ------------------------------------------- import Dumatel main = putStr (shows path $ shows (subterm path t) "\n") where th = bool defaultVariableWeight defaultInitialOpId weightDecls lpo where weightDecls = [] t = parseSingleOrBreak th "bool" "x & (not x)" :: Term path = [] -- :: SubtermPath ------------------------------------------- It cannot choose the Show instance for path = []. But 1) the above `putStr' line contains a subexpression shows (subterm path t) "\n", 2) the imported modules contain the declarations subterm :: SubtermPath -> Term -> Term ... type SubtermPath = [Integer] Hence, it should derive the type for path : [Integer]. Also setting path = [1] or path = [] :: SubtermPath instead of the line path = [] satisfies the compiler. This is not a problem for me to guess to add `:: SubtermPath'. This is a question of curiosity. The compiler sees to which function `path' is fed to, and sees the argument types of this function. Hence, why does not it find the type for `path' ? I am sure that much simpler example is possible (the imported universe is complex), maybe even without overlaps. But maybe, people can explain the effect right for this example as it is? The report is ------------------------------------------ Overlapping instances for Show [a] arising from use of `shows' at GHCBug.hs:5:15-19 Matching instances: Imported from GHC.Show: instance (Show a) => Show [a] Imported from Prelude3: instance Show [Equation] Imported from Prelude3: instance Show [Term] (The choice depends on the instantiation of `a' Use -fallow-incoherent-instances to use the first choice above) In the first argument of `($)', namely `shows path' In the first argument of `putStr', namely `((shows path) $ (shows (subterm path t) "\n"))' In the definition of `main': main = putStr ((shows path) $ (shows (subterm path t) "\n")) where path = [] th = bool defaultVariableWeight defaultInitialOpId weightDecls lpo where weightDecls = [] t = parseSingleOrBreak th "bool" "x & (not x)" :: Term -------------------------------------------------------- Thank you in advance for explanations. ----------------- Serge Mechveliani mechvel@botik.ru
participants (1)
-
Serge D. Mechveliani