#4430: Better support for resolving infix expressions in template haskell
---------------------------------+------------------------------------------
Reporter: reinerp | Owner: reinerp
Type: feature request | Status: patch
Priority: normal | Milestone: 7.4.1
Component: Template Haskell | Version: 6.12.3
Keywords: | Testcase:
Blockedby: | Difficulty:
Os: Unknown/Multiple | Blocking:
Architecture: Unknown/Multiple | Failure: None/Unknown
---------------------------------+------------------------------------------
Changes (by reinerp):
* status: new => patch
Comment:
I've attached some patches which implement {{{UnresolvedInfixE}}} and
{{{UnresolvedInfixP}}} (exactly the same discussion applies to infix
patterns as did to infix expressions, except we don't have to worry about
sections). The approach is following the most recent plan discussed above.
The attached patch changes the behaviour of {{{InfixP}}}, as the previous
behaviour seems almost certainly a bug. In particular, GHC would
reassociate left-biased {{{InfixP}}} splices, (unlike {{{InfixE}}}
splices, which it would leave alone). This actually broke round-tripping
of pattern splices: for example, the pattern match in module B below
currently succeeds:
{{{
{-# LANGUAGE TemplateHaskell #-}
module A where
import Language.Haskell.TH
import Language.Haskell.TH.Quote
data Tree = N
| Tree :+ Tree
infixr :+
p1 = QuasiQuoter undefined (const [p| (N :+ N) :+ N |]) undefined
undefined
{-# LANGUAGE QuasiQuotes #-}
module B where
import A
f = case N :+ (N :+ N) of
[p1|unused|] -> True
}}}
The attached patch changes this so that {{{InfixP}}} trees are never
reassociated, which is consistent with the behaviour of {{{InfixE}}}.
For completeness, I also considered adding unresolved infix constructors
for types, but decided against it: there isn't currently an {{{InfixT}}}
constructor after all, and {{{TypeOperators}}} is a language extension.
My patches add an unexpected failure (TH_pragma), the failure being the
addition of some unnecessary parentheses in {{{-ddump-splices}}}.
Cheers,
Reiner
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4430#comment:12>
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