Skip to content

TH shadowing bind statement triggers -Wunused-matches

{-# LANGUAGE TemplateHaskell #-}
module Test where

import Language.Haskell.TH

m :: (a -> [b]) -> a -> [b]
m =
  $(newName "x" >>= \x ->
    newName "f" >>= \f ->
    lamE [varP f, varP x]
      (doE [ bindS (varP x) (listE [varE f `appE` varE x])
           , noBindS (varE x)])
   )

The splice generates the following expression:

\f x -> do
  x <- [f x]
  x

and -Wunused-matches complains that x is not used, while both bound occurrences are in fact used (the two uses have different types so that's quite certain).

Edited by lyxia
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information