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

#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

#10704: Can't lookup fixities of infix types in Template Haskell -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by rwbarton): Note that those `; infixr 5 :+:` parts are ignored by ghci. {{{ rwbarton@morphism:~/ghc$ ghci-7.10.1 -XTypeOperators GHCi, version 7.10.1: http://www.haskell.org/ghc/ :? for help Prelude> type a :+: b = Either a b; infixr 5 :+: Prelude> :kind! () :+: () :+: () () :+: () :+: () :: * = (() :+: ()) :+: () }}} See #10663. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10704#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10704: Can't lookup fixities of infix types in Template Haskell -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by RyanGlScott): Sorry, I forgot to mention that I was using the HEAD version of GHCi, in which it does work (after fixing #10018): {{{ $ inplace/bin/ghc-stage2 --interactive -XTypeOperators -XTypeFamilies -XMultiParamTypeClasses GHCi, version 7.11.20150727: http://www.haskell.org/ghc/ :? for help λ> class a :=> b; infixr 5 :=> λ> :i :=> class (:=>) a b -- Defined at <interactive>:1:1 infixr 5 :=> λ> type a :+: b = Either a b; infixr 5 :+: λ> :i :+: type (:+:) a b = Either a b -- Defined at <interactive>:3:1 infixr 5 :+: λ> type family a :*: b; infixr 5 :*: λ> :i :*: type family (:*:) a b :: * -- Defined at <interactive>:5:1 infixr 5 :*: }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10704#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10704: Can't lookup fixities of infix types in Template Haskell -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by goldfire): * keywords: => newcomer Comment: Straightforward improvement for anyone who wants to do it. Happy to advise. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10704#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10704: Can't lookup fixities of infix types in Template Haskell -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: | RyanGlScott Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by RyanGlScott): * owner: => RyanGlScott -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10704#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10704: Can't lookup fixities of infix types in Template Haskell -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: | RyanGlScott Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D1109 -------------------------------------+------------------------------------- Changes (by RyanGlScott): * differential: => Phab:D1109 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10704#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10704: Can't lookup fixities of infix types in Template Haskell -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: | RyanGlScott Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D1109 -------------------------------------+------------------------------------- Comment (by goldfire): Now that this is done (see Phab:D1109 -- many thanks!), it looks like it could all be refactored a little more cleanly. What about {{{ module TH.Syntax where ... class ... => Quasi q where ... qReifyFixity :: Name -> q Fixity reifyFixity :: Name -> Q Fixity }}} and then remove all of the `Fixity` fields in `Info`? This should not be a hard change to deal with downstream, and it would declutter things somewhat. It's true that `TyVarI` doesn't have fixities (although they should, morally, except that Haskell provides no way of giving a fixity specification to a type variable), but `PrimTyConI` ''can'' have a fixity: `(->)` has hard-wired fixity `infixr 0`. I'm not wedded to this change, but I do think it's an improvement. Speak up if you have a strong opinion! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10704#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10704: Can't lookup fixities of infix types in Template Haskell -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: | RyanGlScott Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D1109 -------------------------------------+------------------------------------- Comment (by simonpj): That would be fine with me. (comment:6, that is) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10704#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10704: Can't lookup fixities of infix types in Template Haskell -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: | RyanGlScott Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D1109 -------------------------------------+------------------------------------- Comment (by RyanGlScott): You're right, a {{{Quasi}}}-based approach would be way cleaner. I'll update Phab:D1109 to incorporate that. I have one more question about fixities of {{{PrimTyConI}}}, though. It makes sense that {{{(->)}}} has a fixity, now that I actually think about it, but what about prefix types like {{{Char#}}}? Would these always have be {{{infixl 9}}}? If so, should calling {{{qReifyFixity}}} on a {{{TyVarI}}} also yield {{{Fixity 9 InfixL}}}? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10704#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10704: Can't lookup fixities of infix types in Template Haskell -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: | RyanGlScott Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D1109 -------------------------------------+------------------------------------- Comment (by goldfire): Yes, something without a declared fixity defaults to `infixl 9`. But my guess is that the existing fixity-lookup scheme already handles this case. You'll probably have to deal with `(->)` specially (use `BasicTypes.funTyFixity`), but I think that will be the only special case. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10704#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10704: Can't lookup fixities of infix types in Template Haskell -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: | RyanGlScott Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D1109 -------------------------------------+------------------------------------- Comment (by RyanGlScott):
You'll probably have to deal with (->) specially (use BasicTypes.funTyFixity), but I think that will be the only special case.
I was wondering if that was the case, since running {{{:i (->)}}} in GHCi doesn't tell what its fixity is. For that matter, {{{:i (~)}}} doesn't work in GHCi either... I should probably open a separate ticket for this. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10704#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10704: Can't lookup fixities of infix types in Template Haskell -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: | RyanGlScott Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D1109 -------------------------------------+------------------------------------- Comment (by goldfire): I think that last point -- about `:i (~)` -- will be fixed once #10056 is done. If you're looking for a next GHC project, #10056 might be a great next step, once we can figure out the design! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10704#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10704: Can't lookup fixities of infix types in Template Haskell
-------------------------------------+-------------------------------------
Reporter: RyanGlScott | Owner:
| RyanGlScott
Type: feature request | Status: new
Priority: normal | Milestone:
Component: Template Haskell | Version: 7.10.1
Resolution: | Keywords: newcomer
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Revisions: Phab:D1109
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#10704: Can't lookup fixities of infix types in Template Haskell -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: | RyanGlScott Type: feature request | Status: closed Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: fixed | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D1109 -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10704#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC