Skip to content
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

Unexpected behaviour of operators defined in different module #256

Closed
radekm opened this issue Mar 9, 2013 · 5 comments
Closed

Unexpected behaviour of operators defined in different module #256

radekm opened this issue Mar 9, 2013 · 5 comments

Comments

@radekm
Copy link

radekm commented Mar 9, 2013

The following code works as expected (i.e. writes helloA to the console):

module A where

import FFI
import Prelude

infixr 1 ??, >=>

(??) :: a -> (a -> b) -> b
x ?? f = f x

(>=>) :: (a -> Fay b) -> (b -> Fay c) -> a -> Fay c
f >=> g =  \x -> f x >>= g

main :: Fay ()
main = do
  "helloA" ?? return >=> putStrLn

If I move the operators to another module

module Op where

import FFI

infixr 1 ??, >=>

(??) :: a -> (a -> b) -> b
x ?? f = f x

(>=>) :: (a -> Fay b) -> (b -> Fay c) -> a -> Fay c
f >=> g =  \x -> f x >>= g

then the code

module B where

import FFI
import Prelude
import Op

main :: Fay ()
main = do
  "helloB" ?? (return >=> putStrLn)

works too. But if I remove the parentheses around return >=> putStrLn the code stops working (nothing is printed to the console):

module C where

import FFI
import Prelude
import Op

main :: Fay ()
main = do
  "helloC" ?? return >=> putStrLn

I'm using fay-0.14.2.0 and compiling by:

fay --Wall --html-wrapper A.hs
fay --Wall --html-wrapper B.hs
fay --Wall --html-wrapper C.hs
@mgsloan
Copy link
Contributor

mgsloan commented Mar 16, 2013

Looking at the code, I don't think that fay currently handles operator precedence outside of those defined here: http://hackage.haskell.org/packages/archive/haskell-src-exts/1.13.5/doc/html/src/Language-Haskell-Exts-Fixity.html#line-140

Haskell-src-exts does provide a function applyFixities, that allows you to apply fixities after parsing them. Thankfully, there is already a scan of the dependencies in Fay.Compiler.CollectRecords, so fixing this might not be so difficult.

@bergmark
Copy link
Member

This is not quite that easy, we need to first parse the file that uses the imported operator, this parse might fail (src-exts just errors out) because of ambiguous fixities since they are defined in this file's import. So we would need to pre-parse imports without using src-exts and then re-parse with the appropriate fixites.

Luckily haskell-names and the GHC API does this for us so once we migrate to one of these then it will be automagically fixed.

@bergmark
Copy link
Member

Correction: haskell-names doesn't do this.

@bergmark
Copy link
Member

Refs haskell-suite/haskell-names#1

@bergmark
Copy link
Member

Spring cleaning. Lack of activity, it's unlikely that this will happen. Fixity declarations are just too much work since it depends on both parsing and name resolution.

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

No branches or pull requests

3 participants