Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,865
    • Issues 4,865
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 461
    • Merge requests 461
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #2017
Closed
Open
Created Jan 05, 2008 by alfonso.acosta@gmail.com@trac-alfonso.acosta

Normal Guards are internally spliced as Pattern Guards causing compiler warnings

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.

Trac metadata
Trac field Value
Version 6.8.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Template Haskell
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system Unknown
Architecture Unknown
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking