Determining if an instance is provided by the environment
Simon Peyton Jones
simonpj at microsoft.com
Tue May 10 14:10:12 UTC 2016
| I think I need to pass in a 'CtGiven' for 'Show a'. However, I don't
| know what to pass as the evidence to the 'CtGiven'
| constraints. My guess is that it doesn't matter?
Correct, since you just want a yes/no answer. Just make up some fresh Ids with newEvVar.
Simon
| -----Original Message-----
| From: Edward Z. Yang [mailto:ezyang at mit.edu]
| Sent: 07 May 2016 01:34
| To: David Fox <dsf at seereason.com>
| Cc: Simon Peyton Jones <simonpj at microsoft.com>; ghc-devs <ghc-
| devs at haskell.org>
| Subject: Re: Determining if an instance is provided by the environment
|
| Well, I have to write the new variant of this function :)
|
| Simon, I ran into a minor complication: if my instance is something
| like:
|
| instance Show a => Show [a]
|
| I think I need to pass in a 'CtGiven' for 'Show a'. However, I don't
| know what to pass as the evidence to the 'CtGiven'
| constraints. My guess is that it doesn't matter?
|
| Edward
|
| Excerpts from David Fox's message of 2016-05-06 17:06:41 -0700:
| > Is there a way to connect this to template-haskell or haskell-src-
| exts code?
| >
| > On Fri, May 6, 2016 at 4:40 PM, Edward Z. Yang <ezyang at mit.edu>
| wrote:
| >
| > > Thanks Simon, that has all the ingredients I need.
| > >
| > > I wrote some more docs for the function:
| > > https://phabricator.haskell.org/D2180
| > >
| > > Edward
| > >
| > > Excerpts from Simon Peyton Jones's message of 2016-05-06 02:05:31 -
| 0700:
| > > > You probably want a variant on TcDeriv.simplifyDeriv, shorn of
| its
| > > complex error reporting.
| > > >
| > > > Simon
| > > >
| > > > | -----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
| > > > | declaration:
| > > > |
| > > > | 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.
| > > > |
| > > > | Thanks,
| > > > | Edward
| > > > | _______________________________________________
| > > > | ghc-devs mailing list
| > > > | ghc-devs at haskell.org
| > > > |
| > >
| https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2fmail
| > > .ha
| > > > | skell.org%2fcgi-bin%2fmailman%2flistinfo%2fghc-
| > > > | devs&data=01%7c01%7csimonpj%40064d.mgd.microsoft.com
| > > %7c8c304d9b355244c6
| > > > |
| > >
| ee7208d3753be740%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=iWdrnb
| > > 6hC
| > > > | 8pexyVkWNG22G%2fgdO10tCBy8nuCxhnO0M8%3d
| > > _______________________________________________
| > > ghc-devs mailing list
| > > ghc-devs at haskell.org
| > >
| https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2fmail
| > > .haskell.org%2fcgi-bin%2fmailman%2flistinfo%2fghc-
| devs&data=01%7c01%7csimonpj%40064d.mgd.microsoft.com%7c7183659043984718
| 62ec08d3760f3aa2%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=LU%2fYHTo
| y3Y4lSkMdJZD4PrHyAvuWiMOOg0Xm9RE5OTg%3d
| > >
More information about the ghc-devs
mailing list