Skip to content

Respect fixity declarations inside where/let/class in applyFixities. #212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Conversation

barrucadu
Copy link

Both here,

foo = pure 1 <^> pure 2 <^> pure (+) where
  (<^>) = flip (<*>)
  infixr 4 <^>

and here,

class Foo f where
  (<^>) :: Applicative f => f a -> f (a -> b) -> f b
  infixr 4 <^>

foo = pure 1 <^> pure 2 <^> pure (+)

In the body of foo, (<^>) is right-associative (and indeed GHC parses it as such). This patch modifies applyFixities to grab fixities in Binds and ClsDecls and take them into account.


I'm not sure how to write tests for this, as none of the test groups use applyFixities. Should I add another group?

    foo = pure 1 <^> pure 2 <^> pure (+) where
      (<^>) = flip (<*>)
      infixr 4 <^>

In the body of `foo`, `(<^>)` is right-associative (and indeed GHC parses it as
such). This commit makes haskell-src-exts apply any fixity declarations inside
a where (or let) when applying fixities to the expression.
If a typeclass declares an operator, it may also declare the fixity, rather than
declaring the fixity at the top-level.

This means that in the body of `foo` below, `(<^>)` is right-associative:

    class Foo f where
      (<^>) :: Applicative f => f a -> f (a -> b) -> f b
      (<^>) = (<*>)

    foo = pure 1 <^> pure 2 <^> pure (+)

This commit makes haskell-src-exts pick up fixity declarations from within class
declarations when applying fixities.
@barrucadu barrucadu changed the title Respect fixity declarations inside where/let/class in appFixity. Respect fixity declarations inside where/let/class in applyFixities. Apr 11, 2015
@pjonsson
Copy link
Contributor

pjonsson commented Aug 3, 2015

How well do you understand the fixity resolution code in HSE? What is the risk that this change will break something else?

I think I merged a pull request that will break building of this code. Could you please update it against latest HEAD?

Style issue: your let expressions doesn't indent the in an extra column like the surrounding code.

Define extraFix so you can write the code for Let like this: liftM2 Let (extraFix bs bs) $ extraFix bs e

Don't hijack the name fix in the instance for AppFixity Matchto do something else than the other definitions of fix in the file.

@pjonsson pjonsson added this to the 1.17 milestone Aug 7, 2015
@pjonsson
Copy link
Contributor

pjonsson commented Aug 9, 2015

@barrucadu: I apologize for not getting back on this code sooner. If you're busy, can you please respond to the first question and we'll take care of the rest to get this merged for 1.17.

@barrucadu
Copy link
Author

I'm not intimately familiar with the fixity resolution, but have tested this by parsing some complete modules, applying fixities, and checking everything was expected. I would be surprised if anything broke.

@pjonsson pjonsson closed this in 4729e30 Nov 8, 2015
@pjonsson
Copy link
Contributor

pjonsson commented Nov 8, 2015

Merged, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants