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

[ elab ] Support more applicative traversals of TTImp #3130

Merged
merged 2 commits into from
Nov 9, 2023

Conversation

buzden
Copy link
Contributor

@buzden buzden commented Oct 31, 2023

Description

I propose to allow a bit more applicable, applicative mapping of TTImps, which generalises existing mapMTTImp way.

Proposed way allows you to do, for example, the following. Since traversal goes bottom up, from leaves up to the root, there might be not enough information of whether some transformation should be done, or not. Consider you want some transformation happen, but want to cancel it if some condition happens. You may need an original value at this point. The proposed addition of mapMMTTImp (along with existing mapMTTImp) allows this:

record WithOrig a where
  constructor W
  orig : a
  main : Lazy a

Functor WithOrig where
  map f = {orig $= f, main $= f}

Applicative WithOrig where
  pure x = W x x
  W fo fm <*> W xo xm = W (fo xo) (fm xm)

whateverTransformation : TTImp -> TTImp

condTrans : WithOrig TTImp -> WithOrig TTImp
condTrans wo = if cond wo.orig then wo else {main $= whateverTransformation} wo

Running mapMMTTImp condTrans expr, you have both original subexpression and the transformed one inside the condTrans function, allowing you to control precisely whether or not any particular change should be done.

Should this change go in the CHANGELOG?

  • If this is a fix, user-facing change, a compiler change, or a new paper
    implementation, I have updated CHANGELOG.md (and potentially also
    CONTRIBUTORS.md).

@buzden buzden force-pushed the applicative-ttimp-traversals branch from 3edf38c to ddc7c67 Compare November 1, 2023 06:01
@buzden
Copy link
Contributor Author

buzden commented Nov 1, 2023

I also updated one test to reduce the need of constant updates of its golden value on every standard library change, the second commit is for that.

Copy link
Member

@gallais gallais left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Can we call it mapATTImp instead though?

@buzden buzden force-pushed the applicative-ttimp-traversals branch from ddc7c67 to 9dea3ce Compare November 9, 2023 15:09
@buzden
Copy link
Contributor Author

buzden commented Nov 9, 2023

Looks good to me. Can we call it mapATTImp instead though?

Sure, done.

@gallais gallais merged commit 1aff26e into idris-lang:main Nov 9, 2023
22 checks passed
@buzden buzden deleted the applicative-ttimp-traversals branch November 9, 2023 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants