Skip to content

Replace text-format dependency with something more type safe #275

@isomorpheme

Description

@isomorpheme

In a bunch of places, we currently use format from Data.Text.Format to produce strings (e.g. for posting comments, but also log messages). This function is partial: if the format string doesn't have a matching amount of parameters, it fails with an error. Moreover, there's at least one non-obvious way this can happen: in a call like format "x = {}" (show x), the formatting parameters aren't understood as the single string show x, but all of its individual characters because of the infamous type String = [Char] design error. (The fix here is writing [show x] or Only (show x) instead.)

There's some possible alternatives:

  • Use good old-fashioned concatenation of Texts. More foolproof, but cumbersome to read and write, and in principle less efficient.
  • Use a more type-safe formatting library like formatting.
  • In case of logging: use a structured logging library instead of putting contextual data into strings.
  • In case of comments: introduce a sum type of possible comments, and format them centrally (using one of the aforementioned approaches). This has the added benefit of making tests more concise - no need to copy-paste & update similar strings everywhere.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions