#2017: Normal Guards are internally spliced as Pattern Guards causing compiler
warnings
---------------------------------+------------------------------------------
    Reporter:  fons              |       Owner:         
        Type:  bug               |      Status:  new    
    Priority:  normal            |   Milestone:         
   Component:  Template Haskell  |     Version:  6.8.2  
    Severity:  normal            |    Keywords:         
  Difficulty:  Unknown           |    Testcase:         
Architecture:  Unknown           |          Os:  Unknown
---------------------------------+------------------------------------------
 Here is an example

 Foo.hs
 {{{
 {-# OPTIONS_GHC -XTemplateHaskell -ddump-splices #-}

 module Foo where

 import Language.Haskell.TH

 $(do e <- [d| f a b
                 | a == b = a
                 | otherwise = b |]
      runIO (putStrLn $ show e)
      return e)
 }}}

 The example shows that even if the quasiquotes lift the declarations as
 normal guards, they are, for some reson, internally spliced as equivalent
 pattern guards. That shouldn't be a big problem as long as the compiler
 didn't cause warnings for it.


 See the compilation result:

 {{{
 $ ghci Foo.hs
 GHCi, version 6.8.2: http://www.haskell.org/ghc/  :? for help
 Loading package base ... linking ... done.
 [1 of 1] Compiling Foo              ( Foo.hs, interpreted )
 Loading package array-0.1.0.0 ... linking ... done.
 Loading package packedstring-0.1.0.0 ... linking ... done.
 Loading package pretty-1.0.0.0 ... linking ... done.
 Loading package containers-0.1.0.1 ... linking ... done.
 Loading package template-haskell ... linking ... done.
 [FunD f [Clause [VarP a_1627394778,VarP b_1627394779] (GuardedB [(NormalG
 (InfixE (Just (VarE a_1627394778)) (VarE GHC.Base.==) (Just (VarE
 b_1627394779))),VarE a_1627394778),(NormalG (VarE GHC.Base.otherwise),VarE
 b_1627394779)]) []]]
 Foo.hs:1:0:
     Foo.hs:1:0: Splicing declarations
         let
           >>= = (>>=) @ Q $dMonad
           $dMonad = $dMonad
           >> = (>>) @ Q $dMonad
           $dMonad = Language.Haskell.TH.Syntax.$f22
           show = show @ [Dec] $dShow
           $dShow = GHC.Show.$f21 @ Dec $dShow
           $dShow = Language.Haskell.TH.Syntax.$f52
           return = return @ Q $dMonad
           $dMonad = $dMonad
         in
           do e <- [d| :THFake.f a b
                                   | a == b = a
                                   | otherwise = b |]
              runIO @ () (($) @ String @ (IO ()) putStrLn show e)
              return @ [Dec] e
       ======>
         Foo.hs:(7,2)-(11,12)
         f a[a1fQ] b[a1fR]
             | True <- (a[a1fQ] `GHC.Base.==` b[a1fR]) = a[a1fQ]
             | True <- GHC.Base.otherwise = b[a1fR]

 Foo.hs:7:2:
     Warning: accepting non-standard pattern guards (use -XPatternGuards to
 suppress this message)
                  True <- (a[a1fQ] == b[a1fR])

 Foo.hs:7:2:
     Warning: accepting non-standard pattern guards (use -XPatternGuards to
 suppress this message)
                  True <- otherwise
 Ok, modules loaded: Foo.
 *Foo>
 }}}

 The logical thing a user would expect is to see the guards spliced as:

 {{{
    | (a[a1fQ] `GHC.Base.==` b[a1fR]) = a[a1fQ]
 }}}

 and not

 {{{
    | True <- (a[a1fQ] `GHC.Base.==` b[a1fR]) = a[a1fQ]
 }}}


 As expected and suggested by the compiler the warnings are silenced with
 the -XPatternGuards.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2017>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to