Ticket #1541 (closed bug: fixed)

Opened 6 years ago

Last modified 14 months ago

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 Difficulty: Unknown
Test Case: th/T1541 Blocked By:
Blocking: Related Tickets:

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

th-fixity.txt Download (0.6 KB) - added by ekmett@… 6 years ago.
minimalist example

Change History

Changed 6 years ago by guest

  • component changed from Compiler to Template Haskell
  • summary changed from No way to set build fixity declarations in template haskell to No 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 6 years ago by ekmett@…

minimalist example

Changed 6 years ago by igloo

  • milestone set to 6.8

Changed 6 years ago by simonpj

  • milestone changed from 6.8 to 6.1

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

Simon

Changed 5 years ago by simonmar

  • architecture changed from Multiple to Unknown/Multiple

Changed 5 years ago by simonmar

  • os changed from Multiple to Unknown/Multiple

Changed 4 years ago by igloo

  • milestone changed from 6.10 branch to _|_

Changed 3 years ago by reinerp

  • owner set to reinerp
  • failure set to 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?

Changed 3 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

Changed 15 months 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.

Changed 15 months 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.

Changed 14 months 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(-)

Changed 14 months ago by simonpj

  • status changed from new to closed
  • testcase set to th/T1541
  • resolution set to fixed

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

Simon

Changed 14 months 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.