haskellyesod

Weird unused-top-binds warning in Yesod / Haskell


When compiling the following Yesod / Haskell code ( Main.hs )

data App = App

mkYesod "App" [parseRoutes|
/from/php/to/dhscanner/ast FromPhpR POST
/from/py/to/dhscanner/ast FromPyR POST
/from/rb/to/dhscanner/ast FromRbR POST
/from/js/to/dhscanner/ast FromJsR POST
/healthcheck HealthcheckR GET
|]

instance Yesod App

I get the following weird warning1:

src/Main.hs:40:1: warning: [GHC-40910] [-Wunused-top-binds]
    Defined but not used: type constructor or class ‘Widget’
   |
40 | mkYesod "App" [parseRoutes|
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

src/Main.hs:40:1: warning: [GHC-40910] [-Wunused-top-binds]
    Defined but not used: ‘resourcesApp’
   |
40 | mkYesod "App" [parseRoutes|
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

The docs day that:

[ ... ] warn if a binding brings into scope a variable that is not used, except if the variable’s name starts with an underscore

But as a user of Yesod, I can not control variables defined there ( right? )


1 everything works fine, I just don't understand the warning


Solution

  • mkYesod is a TemplateHaskell function that defines symbols in the module you call it, they're not treated any differently than symbols you defined by "hand".

    If the warning bothers you you can simply export Widget, if you're using the shakespeare stuff Yesod comes with for templating you'll probably want to do that anyway as soon as your app is more than one file.