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

Audit usages of fold_right #1688

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Audit usages of fold_right #1688

wants to merge 5 commits into from

Conversation

michael-schwarz
Copy link
Member

@michael-schwarz michael-schwarz commented Feb 18, 2025

This PR replaces usages of fold_right with usages of fold_left wherever there is obviously no difference between both. This also raised an instances where I am unsure if the code in Goblint is correct.

@michael-schwarz michael-schwarz added the cleanup Refactoring, clean-up label Feb 18, 2025
@sim642 sim642 linked an issue Feb 18, 2025 that may be closed by this pull request
| None -> None
| Some st ->
let reachable acc e =
Option.bind acc (fun st ->
Copy link
Member

Choose a reason for hiding this comment

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

This could even use let-punning after let open GobOption.Syntax in or something.

Copy link
Member Author

Choose a reason for hiding this comment

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

I played around with it, but was unconvinced whether it is easier / more beautiful:

    let reachable acc e =
      let open GobOption.Syntax in
      let* st = acc in
      let ad = ask.f (Queries.ReachableFrom e) in
      if Queries.AD.is_top ad then
        None
      else
        Some (Queries.AD.join ad st)
    in

Copy link
Member Author

Choose a reason for hiding this comment

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

@jerhard @DrMichaelPetter @karoliineh @vesalvojdani Opinions on monadic syntax or not?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Me as a contributor more on the novice side would rather see the explicit binding version instead of the let-punning - call me a simpleton, but I like it better the explicit way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Refactoring, clean-up
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigate instances of fold_right
3 participants