Comments (12)
This is also an issue in Fay (old test case)
data SomeRec = SomeRec { a :: Int, b :: Int }
fun :: SomeRec -> SomeRec
fun SomeRec{a} = SomeRec{a=a+1, b=10}
main = do
print (fun (SomeRec{a=1, b=2}))
where the a in a+1
resolves to Main.a
instead of just a
.
from haskell-names.
Note: full support is contingent on haskell-suite/haskell-src-exts#35
from haskell-names.
HEAD
(7ba836e) now has support for named field puns (but not for wildcards yet).
from haskell-names.
Record wildcard patterns are now in HEAD
(d543f12).
Regarding record wildcard constructions, I'm thinking of adding a new constructor to NameInfo
to annotate the wildcard with something like [(OrigName, NameInfo l)]
, where every tuple corresponds to a field binding (OrigName
is the record selector, NameInfo l
describes the assigned value).
@bergmark, would that work for you?
Also, do you need any annotations for wildcards in patterns? Right now names from wildcards are introduced into the scope, but wildcards themselves are not annotated.
from haskell-names.
Great news! :)
We do need some way of looking up the names for wildcard patterns for code generation, so if you could add that annotation it would be nice. We do that lookup by ourselves right now so it's not critical.
Thanks!
from haskell-names.
Done (as of 66179da). @bergmark, could you take a look at the interface and tell if it suits your needs? (See RecPatWildcard
and RecExpWildcard
constructors of Language.Haskell.Names.Annotated.NameInfo
from haskell-names.
It works!
It's a bit more verbose than what we already have since we need the locally bound names rather than what they resolve to (since we access record fields in JS with rec.field
rather than M.field(rec)
), but if we move this into the desugaring phase it will come in handy. Either way haskell-names doesn't crash on it anymore :)
Please let me know when this is released, and thanks again!
from haskell-names.
By "a bit more verbose" do you mean just that you need to unpack OrigName
to get a Name
? Could you point me to the code that deals with this, so that I can see whether I can improve anything on my side?
I plan to make a release as soon as we're done with this issue.
from haskell-names.
Right, we already have a map from a constructor's qualified name to its fields so we can just do a lookup on that. But thinking about it more I should perhaps switch anyways...:
wildcardFields1 con = map (UnQual ()) <$> recToFields con
wildcardFields2 l = case l of
Scoped (RecExpWildcard es) _ -> map (\(OrigName _ o) -> unQualify $ gname2Qname o) . map fst $ es
_ -> []
from haskell-names.
EHM! There was a bug in the old code, it didn't handle R{a=n,..}
properly. Definitely switching now :)
from haskell-names.
Yes, that stuff is not trivial at all ;)
E.g. you must only substitute the fields that have corresponding values in scope, except when those values themselves are record selectors of that constructor.
OrigName
has field selectors, so you can use those instead of a pattern match in the code above. I also just added field selectors to GName
.
If there's anything else I can do to make your life easier, feel free to open separate issues.
from haskell-names.
haskell-names-0.3 has been uploaded
from haskell-names.
Related Issues (20)
- Resolving local function's type signatures
- Bump-up to 'haskell-src-exts-1.20.1' (also support build with stack) HOT 2
- Is there a tool to update the data/baseEnvironment files? HOT 3
- haskell-src-exts dependency HOT 4
- Tests fail (new aeson?) probably due to json field ordering
- GADT constructors not Value Binders
- Promoted names annotated in wrong context
- In tests/annotations/FnBind.hs, shouldn't f be global? HOT 1
- Add haskell-names back to stackage HOT 4
- test failure, missing extra-source-file HOT 2
- Return computed tables with annotate HOT 2
- Rename `Symbol` to `Entity`.
- Overlapping instances for GTraversable HOT 1
- Remember providence of Punned and Wildcarded named HOT 4
- Document `resolve` behaviour better HOT 2
- Allow to pass -XNoImplicitPrelude to 'importTable' explicitly
- Support QuasiQuotes scoping
- Support recent versions of aeson and traverse-with-class
- Doesn't resolve TemplateHaskell splices and top-level usages
- Please, release 0.9.0 version HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from haskell-names.