Skip to content

[list-ops] Make foldl' call unambiguous.#1298

Open
IsaacG wants to merge 3 commits into
exercism:mainfrom
IsaacG:listops
Open

[list-ops] Make foldl' call unambiguous.#1298
IsaacG wants to merge 3 commits into
exercism:mainfrom
IsaacG:listops

Conversation

@IsaacG
Copy link
Copy Markdown
Member

@IsaacG IsaacG commented May 16, 2026

/solution/test/Tests.hs:80:9: error: [GHC-87543]
    Ambiguous occurrence ‘foldl'’.
    It could refer to
       either ‘Prelude.foldl'’,
              imported from ‘Prelude’ at test/Tests.hs:(8,1)-(16,5)
              (and originally defined in ‘ghc-internal-9.1003.0:GHC.Internal.Data.Foldable’),
           or ‘ListOps.foldl'’,
              imported from ‘ListOps’ at test/Tests.hs:22:7-12.
   |
80 |         foldl' (flip (:)) [] "asdf" `shouldBe` "fdsa"
   |         ^^^^^^

```
/solution/test/Tests.hs:80:9: error: [GHC-87543]
    Ambiguous occurrence ‘foldl'’.
    It could refer to
       either ‘Prelude.foldl'’,
              imported from ‘Prelude’ at test/Tests.hs:(8,1)-(16,5)
              (and originally defined in ‘ghc-internal-9.1003.0:GHC.Internal.Data.Foldable’),
           or ‘ListOps.foldl'’,
              imported from ‘ListOps’ at test/Tests.hs:22:7-12.
   |
80 |         foldl' (flip (:)) [] "asdf" `shouldBe` "fdsa"
   |         ^^^^^^
```
@github-actions
Copy link
Copy Markdown

This PR touches files which potentially affect the outcome of the tests of an exercise. This will cause all students' solutions to affected exercises to be re-tested.

If this PR does not affect the result of the test (or, for example, adds an edge case that is not worth rerunning all tests for), please add the following to the merge-commit message which will stops student's tests from re-running. Please copy-paste to avoid typos.

[no important files changed]

For more information, refer to the documentation. If you are unsure whether to add the message or not, please ping @exercism/maintainers-admin in a comment. Thank you!

Copy link
Copy Markdown
Contributor

@MatthijsBlom MatthijsBlom left a comment

Choose a reason for hiding this comment

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

I think a [no important files changed] would be fitting.


Prior to base-4.20.0.0 (bundled with GHC 9.10), foldl' was not re-exported by the Prelude. But from base-4.20.0.0 onward it is, hence the error that the proposed change fixes.

All other names defined in ListOps were already exported by the Prelude. This conflict was solved by hiding these while importing the Prelude. Rather than disambiguating all its uses, add foldl' to this import list.


The solution stub file should be patched as well.

@IsaacG
Copy link
Copy Markdown
Member Author

IsaacG commented May 16, 2026

I think a [no important files changed] would be fitting.

I completely agree. That needs to be in the merge message when the track maintainer merges this PR.

The solution stub file should be patched as well.

Done.

Thanks for the explanation and details!

@MatthijsBlom
Copy link
Copy Markdown
Contributor

MatthijsBlom commented May 16, 2026

Both …/list-ops/.meta/…/ListOps.hs and …/list-ops/test/Tests.hs are good now.

By "the solution stub file" I meant …/list-ops/src/ListOps.hs. That one should receive the same patch as the other two.


Hiding a nonexistent export gives rise to merely a GHC-61689 -Wdodgy-imports warning, so it looks like this change is backwards-compatible.


...Except apparently the tests have -Werror=dodgy-imports. I guess as a consequence of a -Werror=all or something somewhere.

@IsaacG
Copy link
Copy Markdown
Member Author

IsaacG commented May 16, 2026

By "the solution stub file" I meant …/list-ops/src/ListOps.hs. That one should receive the same patch as the other two.

Woops. Missed that one. Added now.

@IsaacG
Copy link
Copy Markdown
Member Author

IsaacG commented May 16, 2026

Eh. This PR was meant in service of the test runner upgrade. If that lands first, a test rerun ought to pass here.

Unrelated, there's a bunch of other PRs in this repo worth a look, too!

@MatthijsBlom
Copy link
Copy Markdown
Contributor

I think the tests fail because of

--pedantic `# Enable -Wall and -Werror. `\

I guess they could be made to pass again by adding --ghc-options="-Wwarn=dodgy-imports" to that stack call.
But we could also just wait until the track moves on to use base-4.20+ (GHC 9.10+).

@IsaacG
Copy link
Copy Markdown
Member Author

IsaacG commented Jun 6, 2026

@tofische With the test runner updated, it might be worth rerunning the failed check here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants