Determining if an instance is provided by the environment
Simon Peyton Jones
simonpj at microsoft.com
Fri May 6 09:05:31 UTC 2016
You probably want a variant on TcDeriv.simplifyDeriv, shorn of its complex error reporting.
| -----Original Message-----
| From: ghc-devs [mailto:ghc-devs-bounces at haskell.org] On Behalf Of
| Edward Z. Yang
| Sent: 06 May 2016 00:21
| To: ghc-devs <ghc-devs at haskell.org>
| Subject: Determining if an instance is provided by the environment
| Hello all,
| Suppose I have a ClsInst from typechecking the following instance
| instance Show [Char] -- i.e. String
| I'd now like to answer the question: "Is this instance 'provided'
| by the instance environment?" For example, this instance is provided
| given that I have these two instances in the environment:
| instance Show a => Show [a] -- (1)
| instance Show Char -- (2)
| However, if I have just instance (1) in the environment, it's not
| provided (and if you tried to use show "foo", you'd get the error that
| Char is not an instance of Show.)
| Is there are convenient way to do this from TcM? With 'tcMatchTys'
| and I can easily test if there is some instance in the environment
| which *matches* my instance head (e.g., Show [a] matches Show [Char])
| but this doesn't tell me if all the resulting constraints are solvable.
| ghc-devs mailing list
| ghc-devs at haskell.org
More information about the ghc-devs