Skip to content

Can't lookup fixities of infix types in Template Haskell

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.

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