faylang / fay

A proper subset of Haskell that compiles to JavaScript
https://github.com/faylang/fay/wiki
BSD 3-Clause "New" or "Revised" License
1.29k stars 86 forks source link

Export of overloaded functions and operators #454

Closed schnecki closed 6 years ago

schnecki commented 6 years ago

It seems like Fay is not correctly exporting some infix operators and functions like return. I have a simple Parser library, where (as we have no type classes) I export e.g. bind directly and use it in desugared style. However, the bind operator does not work outside the module, whereas inside it works and once I change the (>>=) operator to the name bind it compiles correctly. Btw GHC compiles the file in all variants (for the Haskell server side implementation).

Unable to compile Fay module "Cdn/FtpBrowser":

ghc: 
fay-shared/Shared/Cdn/FtpBrowser.hs:54:76: error:
    parse error on input ‘P.>>=’

CallStack (from HasCallStack):
  error, called at ./Yesod/Fay.hs:505:3 in yesod-fay-0.8.2-EnznqQxANr7EJSLbxziD2P:Yesod.Fay

Similarly I cannot export a function named return:

Unable to compile Fay module "Cdn/FtpBrowser":

unable to resolve qualified names (this might be a bug):P.return

If I change the name it works. Are there different keywords in Fay?

bergmark commented 6 years ago

There might be some bug with qualified exports or imports, did you try import Prelude hiding ((>>=), return) and importing yours unqualified to see if that works? Might not be what you want but it'd help diagnose the issue.

The parse error from P.>>= could also be because of limitations in haskell-src-exts. IIRC it only handles fixities for operators in base and it might not consider P.>>= the same as >>=. The consequence of this limitation is also that you can't define a custom fixity for e.g. your >>=, but I don't think you want to do that anyway. Using unqualified imports might resolve this issue as well.

schnecki commented 6 years ago

Unqualified imports worked.