[GHC] #10704: Can't lookup fixities of infix types in Template Haskell

GHC ghc-devs at haskell.org
Tue Jul 28 21:05:31 UTC 2015


#10704: Can't lookup fixities of infix types in Template Haskell
-------------------------------------+-------------------------------------
              Reporter:              |             Owner:
  RyanGlScott                        |
                  Type:  feature     |            Status:  new
  request                            |
              Priority:  normal      |         Milestone:
             Component:  Template    |           Version:  7.10.1
  Haskell                            |
              Keywords:              |  Operating System:  Unknown/Multiple
          Architecture:              |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
             Test Case:              |        Blocked By:
              Blocking:              |   Related Tickets:
Differential Revisions:              |
-------------------------------------+-------------------------------------
 Currently, Template Haskell allows you to reify the fixity of regular
 functions, typeclass functions, and data constructors:

 {{{
 λ> import Language.Haskell.TH

 λ> $(reify '($) >>= stringE . show)
 "VarI GHC.Base.$ (ForallT [KindedTV a_822083586 StarT,KindedTV b_822083587
 (ConT GHC.Prim.OpenKind)] [] (AppT (AppT ArrowT (AppT (AppT ArrowT (VarT
 a_822083586)) (VarT b_822083587))) (AppT (AppT ArrowT (VarT a_822083586))
 (VarT b_822083587)))) Nothing (Fixity 0 InfixR)"

 λ> $(reify '(+) >>= stringE . show)
 "ClassOpI GHC.Num.+ (ForallT [KindedTV a_1627404054 StarT] [AppT (ConT
 GHC.Num.Num) (VarT a_1627404054)] (AppT (AppT ArrowT (VarT a_1627404054))
 (AppT (AppT ArrowT (VarT a_1627404054)) (VarT a_1627404054)))) GHC.Num.Num
 (Fixity 6 InfixL)"

 λ> $(reify '(:%) >>= stringE . show)
 "DataConI GHC.Real.:% (ForallT [KindedTV a_1627412324 StarT] [] (AppT
 (AppT ArrowT (VarT a_1627412324)) (AppT (AppT ArrowT (VarT a_1627412324))
 (AppT (ConT GHC.Real.Ratio) (VarT a_1627412324))))) GHC.Real.Ratio (Fixity
 9 InfixL)"
 }}}

 However, you can't do the same for infix typeclasses, type constructors,
 or type families:

 {{{
 λ> :set -XTypeOperators -XTypeFamilies -XMultiParamTypeClasses

 λ> class a :=> b; infixr 5 :=>
 λ> $(reify ''(:=>) >>= stringE . show)
 "ClassI (ClassD [] Ghci5.:=> [KindedTV a_1627424666 StarT,KindedTV
 b_1627424667 StarT] [] []) []"

 λ> type a :+: b = Either a b; infixr 5 :+:
 λ> $(reify ''(:+:) >>= stringE . show)
 "TyConI (TySynD Ghci7.:+: [KindedTV a_1627426783 StarT,KindedTV
 b_1627426784 StarT] (AppT (AppT (ConT Data.Either.Either) (VarT
 a_1627426783)) (VarT b_1627426784)))"

 λ> $(reify ''(:*:) >>= stringE . show)
 "FamilyI (FamilyD TypeFam Ghci9.:*: [KindedTV a_1627426938 StarT,KindedTV
 b_1627426939 StarT] (Just StarT)) []"
 }}}

 We should add a {{{Fixity}}} field to {{{ClassI}}}, {{{TyConI}}}, and
 {{{FamilyI}}} to make them consistent with the other {{{Info}}}
 constructors that allow for infix things.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10704>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list