Skip to content

Clean up unnecessary usage of String type in favour of Text#1675

Merged
david-yz-liu merged 7 commits intoCourseography:masterfrom
Purplegaze:overloadedstrings-cleanup
Mar 6, 2026
Merged

Clean up unnecessary usage of String type in favour of Text#1675
david-yz-liu merged 7 commits intoCourseography:masterfrom
Purplegaze:overloadedstrings-cleanup

Conversation

@Purplegaze
Copy link
Contributor

@Purplegaze Purplegaze commented Mar 5, 2026

Proposed Changes

Removes unnecessary uses of Data.Text.pack and simplifies code to avoid usage of the String type to account for the OverloadedStrings compiler extension.

...

Screenshots of your changes (if applicable)

Type of Change

(Write an X or a brief description next to the type or types that best describe your changes.)

Type Applies?
🚨 Breaking change (fix or feature that would cause existing functionality to change)
New feature (non-breaking change that adds functionality)
🐛 Bug fix (non-breaking change that fixes an issue)
🎨 User interface change (change to user interface; provide screenshots)
♻️ Refactoring (internal change to codebase, without changing functionality) X
🚦 Test update (change that only adds or modifies tests)
📦 Dependency update (change that updates a dependency)
🔧 Internal (change that only affects developers or continuous integration)

Checklist

(Complete each of the following items for your pull request. Indicate that you have completed an item by changing the [ ] into a [x] in the raw text, or by clicking on the checkbox in the rendered description on GitHub.)

Before opening your pull request:

  • I have performed a self-review of my changes.
    • Check that all changed files included in this pull request are intentional changes.
    • Check that all changes are relevant to the purpose of this pull request, as described above.
  • I have added tests for my changes, if applicable.
    • This is required for all bug fixes and new features.
  • I have updated the project documentation, if applicable.
    • This is required for new features.
  • If this is my first contribution, I have added myself to the list of contributors.
  • I have updated the project Changelog (this is required for all changes).

After opening your pull request:

  • I have verified that the CircleCI checks have passed.
  • I have requested a review from a project maintainer.

Questions and Comments

Will post in a separate comment below.

@Purplegaze
Copy link
Contributor Author

CourseControllerTests, IntersectionTests, Config: removed T.pack for string literals.
Svg/Parser: Used T.splitOn instead of List.splitOn to avoid converting to String type.

The remaining String to Text conversions fall into these categories:

  1. Usage of show (appears several times, e.g. DynamicGraphs/WriteRunDot.hs, Export/TimetableImageCreator.hs, Svg/Builder.hs)
    • It looks like the external package text-show provides a Text equivalent of the Show typeclass, which I could try importing if this is a worthwhile change.
  2. Usage of String within the local Req datatype
    • Changing this datatype to use Text instead of String sounds quite breaking, considering the wide variety of functions it's used in.
  3. String type used within Parsec parsers (e.g. parseCourseTitle in WebParsing/ArtSciParser.hs)
    • These constructions iterate through characters one at a time by design, so somehow rewriting them using Text sounds like it'd be unnatural and wouldn't provide much performance benefit.

Would like a follow-up on whether you think any of these categories should also be simplified, or if the current changes are enough.

Side question: what's the easiest way to test whether the Svg/Parser changes work as expected? Should I try to write tests for this file, since I've altered it and it doesn't have any, or are these tangentially tested somewhere else?

@Purplegaze Purplegaze changed the title Overloadedstrings cleanup Clean up unnecessary usage of String type in favour of Text Mar 5, 2026
@coveralls
Copy link

coveralls commented Mar 5, 2026

Pull Request Test Coverage Report for Build 573f628e-7148-48ae-918f-aa3f439e1370

Details

  • 6 of 10 (60.0%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 56.41%

Changes Missing Coverage Covered Lines Changed/Added Lines %
app/Config.hs 0 1 0.0%
app/Export/TimetableImageCreator.hs 0 1 0.0%
app/Svg/Builder.hs 3 5 60.0%
Totals Coverage Status
Change from base Build 23a74828-109c-43b3-a396-9b446ca521b1: 0.0%
Covered Lines: 2280
Relevant Lines: 3968

💛 - Coveralls

@Purplegaze Purplegaze requested a review from david-yz-liu March 6, 2026 01:04
@Purplegaze
Copy link
Contributor Author

(see comment above, not sure if I should have pressed "request review" instead of sending a Slack message yesterday)

Copy link
Contributor

@david-yz-liu david-yz-liu left a comment

Choose a reason for hiding this comment

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

Hi @Purplegaze, thanks for making this PR! Sending a message on Slack was fine, but so was requesting a review (either is an acceptable way to flag an in-progress PR to my attention).

Regarding your notes about the remaining String instances: you can add the text-show package to our dependencies, that's a nice find. Don't worry about changing the Req datatype or the Parsec parsers for this PR.

You're right that there aren't tests currently for the Svg.Parser module. Don't worry about adding test cases for them here, but you can test your changes manually by re-running the database-graphs command.

@Purplegaze Purplegaze marked this pull request as ready for review March 6, 2026 17:05
@Purplegaze
Copy link
Contributor Author

Thanks! Should be ready for review now.

@Purplegaze Purplegaze requested a review from david-yz-liu March 6, 2026 17:06
Copy link
Contributor

@david-yz-liu david-yz-liu left a comment

Choose a reason for hiding this comment

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

Nice work, @Purplegaze!

@david-yz-liu david-yz-liu merged commit 3b2886b into Courseography:master Mar 6, 2026
4 checks passed
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.

3 participants