[GHC] #16169: Unused variable warning affects compositionality when generating code
GHC
ghc-devs at haskell.org
Fri Jan 11 12:03:26 UTC 2019
#16169: Unused variable warning affects compositionality when generating code
-------------------------------------+-------------------------------------
Reporter: mpickering | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.6.3
Keywords: | Operating System: Unknown/Multiple
Architecture: | Type of failure: None/Unknown
Unknown/Multiple |
Test Case: | Blocked By:
Blocking: | Related Tickets:
Differential Rev(s): | Wiki Page:
-------------------------------------+-------------------------------------
If I'm generating a program using template haskell, I might define
a combinator to help me generate lambdas.
{{{
type Code a = Q (TExp a)
_lam :: (Code a -> Code b) -> Code (a -> b)
_lam f = [|| \a -> $$(f [|| a ||]) ||]
}}}
However, if I now pass a constant function into `_lam`, the generated code
contains an unused variable `a` that I can do nothing about and desire not
to do anything about.
{{{
c5 :: Code (a -> Int)
c5 = _lam (const [|| 5 ||])
}}}
However, GHC decides that it's wise to warn me about this when I splice it
in.
{{{
> $$c5
F2.hs:6:5: warning: [-Wunused-matches] Defined but not used: ‘a’
|
6 | q = $$c5
| ^^^
}}}
As Ryan will tell you, I'm against emitting warnings from generated code
as it breaks the abstraction. The code that is generated is guaranteed to
be type and scope correct but any aesthetic warning is irrelevant to the
consumer.
I see it in precisely the same way as warning if we use a function that
contains an unused variable in a library. Once the definition is exported
from the library, its definition is opaque. The same principle should be
applied to code generated by template haskell.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/16169>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list