Git Product home page Git Product logo

Comments (12)

bergmark avatar bergmark commented on July 19, 2024

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.

UnkindPartition avatar UnkindPartition commented on July 19, 2024

Note: full support is contingent on haskell-suite/haskell-src-exts#35

from haskell-names.

UnkindPartition avatar UnkindPartition commented on July 19, 2024

HEAD (7ba836e) now has support for named field puns (but not for wildcards yet).

from haskell-names.

UnkindPartition avatar UnkindPartition commented on July 19, 2024

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.

bergmark avatar bergmark commented on July 19, 2024

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.

UnkindPartition avatar UnkindPartition commented on July 19, 2024

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.

bergmark avatar bergmark commented on July 19, 2024

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.

UnkindPartition avatar UnkindPartition commented on July 19, 2024

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.

bergmark avatar bergmark commented on July 19, 2024

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.

bergmark avatar bergmark commented on July 19, 2024

EHM! There was a bug in the old code, it didn't handle R{a=n,..} properly. Definitely switching now :)

from haskell-names.

UnkindPartition avatar UnkindPartition commented on July 19, 2024

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.

UnkindPartition avatar UnkindPartition commented on July 19, 2024

haskell-names-0.3 has been uploaded

from haskell-names.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.