resolving Show instance
Simon Peyton-Jones
simonpj at microsoft.com
Thu Jun 30 07:08:33 EDT 2005
path gets the inferred type
path :: forall a. [a]
This polymorphic type is instantiated once when it is passed to
'subterm' and again, quite separately, when it is passed to 'shows'.
Simon
| -----Original Message-----
| From: glasgow-haskell-users-bounces at haskell.org
[mailto:glasgow-haskell-users-
| bounces at haskell.org] On Behalf Of Serge D. Mechveliani
| Sent: 30 June 2005 11:58
| To: glasgow-haskell-users at haskell.org
| Subject: resolving Show instance
|
| 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 at botik.ru
| _______________________________________________
| Glasgow-haskell-users mailing list
| Glasgow-haskell-users at haskell.org
| http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
More information about the Glasgow-haskell-users
mailing list