Opened 10 years ago

Closed 5 years ago

Last modified 5 years ago

#1541 closed bug (fixed)

No way at all to set fixity for infix operators defined in template haskell

Reported by: guest Owned by: reinerp
Priority: normal Milestone:
Component: Template Haskell Version: 6.6.1
Keywords: Cc: eir@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: th/T1541
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

There appears to be no way to create fixity declarations in template haskell.

As a result, I can define a complicated sequence of infix identifiers in a template Haskell expression, but I still have to go through and hand-enter the {infixl, infixr, infix} declarations at the top. Admittedly the fixities it creates won't be used by the current module, but importers of the module should still see them.

There is a precedent for template Haskell handling some fixity concerns because all of the Info pieces of template Haskell tell you the fixities of the infix operators in question.

Attachments (1)

th-fixity.txt (588 bytes) - added by ekmett@… 10 years ago.
minimalist example

Download all attachments as: .zip

Change History (14)

comment:1 Changed 10 years ago by guest

Component: CompilerTemplate Haskell
Summary: No way to set build fixity declarations in template haskellNo way at all to set fixity for infix operators defined in template haskell

There is no way at all to give a fixity to an infix operation defined in template Haskell.

They aren't in scope in the module itself at the time infix* declarations are parsed.

They aren't considered in scope and thus available for changing fixity in other modules.

Changed 10 years ago by ekmett@…

Attachment: th-fixity.txt added

minimalist example

comment:2 Changed 10 years ago by igloo

Milestone: 6.8

comment:3 Changed 10 years ago by simonpj

Milestone: 6.86.1

This seems like a reasonable feature request. Would anyone like to tackle it?

Simon

comment:4 Changed 9 years ago by simonmar

Architecture: MultipleUnknown/Multiple

comment:5 Changed 9 years ago by simonmar

Operating System: MultipleUnknown/Multiple

comment:6 Changed 8 years ago by igloo

Milestone: 6.10 branch_|_

comment:7 Changed 7 years ago by reinerp

Owner: set to reinerp
Type of failure: None/Unknown

I propose to implement this by adding the following constructor to Language.Haskell.TH.Dec:

 data Dec = 
     ...
     | FixityD Name Fixity
     ...

and making the appropriate changes in Convert.lhs and DsMeta.hs.

This definition allows constructing fixity declarations which refer to operators defined in other modules (say). It seems easiest for Template Haskell not to be concerned by this, and defer checking for such errors to the renamer.

Thoughts?

comment:8 Changed 7 years ago by simonpj

That looks plausible to me. The question of fixity declarations for things defined elsewhere is no different than for pragmas or type signatures, so I don't think it's an issue.

Simon

comment:9 Changed 5 years ago by goldfire

Cc: eir@… added

I'm writing a TH program that, among other things, takes operators defined by a client program and makes new operators based on those. Having the ability to produce a fixity declaration would be great.

comment:10 Changed 5 years ago by mgsloan1

++ I want this too!

My suggestion would be to make it the following:

 data Dec = 
     ...
     | FixityD Fixity Name
     ...

As nearly all of the TH constructors use the order of the syntax for the order of the fields.

comment:11 Changed 5 years ago by simonpj@…

commit ef2491a378bbe0fcaea7aa2ad69bc82a838f6a59

Author: Simon Peyton Jones <simonpj@microsoft.com>
Date:   Wed Mar 14 17:28:32 2012 +0000

    Add fixity declarations to Template Haskell (Trac #1541)
    
    There is an accompanying patch to the template-haskell library

 compiler/deSugar/DsMeta.hs |   75 ++++++++++++++++++++++++++++++++++++-------
 compiler/hsSyn/Convert.lhs |   30 ++++++++++++-----
 2 files changed, 83 insertions(+), 22 deletions(-)

comment:12 Changed 5 years ago by simonpj

Resolution: fixed
Status: newclosed
Test Case: th/T1541

I've finally done this, closing a 5-year-old ticket. Hurrah.

Simon

comment:13 Changed 5 years ago by simonpj@…

commit 55372bcd814aa17413ec1fd8ca23a0b5064e784c

Author: Simon Peyton Jones <simonpj@microsoft.com>
Date:   Wed Mar 14 17:28:32 2012 +0000

    Add fixity declarations to Template Haskell (Trac #1541)
    
    There is an accompanying patch to the template-haskell library

 compiler/deSugar/DsMeta.hs |   75 ++++++++++++++++++++++++++++++++++++-------
 compiler/hsSyn/Convert.lhs |   30 ++++++++++++-----
 2 files changed, 83 insertions(+), 22 deletions(-)
Note: See TracTickets for help on using tickets.