Skip to content

Add instances of IsString (List Char) #2756

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

Merged
merged 5 commits into from
Jul 17, 2025

Conversation

rvs314
Copy link
Contributor

@rvs314 rvs314 commented Jun 30, 2025

As discussed in #2745, adds instances of IsString (List Char) to Data.List.Instances and Data.List.Literals. If these changes need tests I can add some.

There's a small potential for confusion in the current configuration, however. The Constraint field of List Char's isString is the constant function λ _ → ⊤, so an instance of must be in scope. This means that a user which includes Data.List.Instances but does not have tt defined will get an error.

For example,
open import Data.List.Base
open import Data.Char.Base
open import Data.List.Literals
open import Agda.Builtin.FromString

theListOfChars : List Char
theListOfChars = "foobar"

{- No instance of type isString .IsString.Constraint "foobar" was
   found in scope.
   when checking that "foobar" is a valid argument to a function of
   type
   {a : Agda.Primitive.Level} {A : Set a} ⦃ r : IsString A ⦄
   (s : Agda.Builtin.String.String) ⦃ _ : r .IsString.Constraint s ⦄ →
   A -}

@rvs314
Copy link
Contributor Author

rvs314 commented Jun 30, 2025

Additionally, the HACKING.md file mentions that related modules should have parallel updates when reasonable. It seems like adding similar instance declarations for something like Data.List.NonEmpty, Data.Vec, or Codata.Sized.Colist would fit that bill, but no IsString instances are defined in those modules. I'd be happy to add those instances as well, if the court would look favorably upon it.

@JacquesCarette
Copy link
Contributor

I would think those would be worth a parallel PR. And it might not be bad to wait a day, so see what comments come in on this one.

{ Constraint = λ _ → ⊤
; fromString = λ s → toList s
}
instance
Copy link
Contributor

Choose a reason for hiding this comment

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

So I think this is backwards (unfortunately). We want instances declared in Data.List.Instances so that people who don't want them can avoid them entirely.

We do want isString defined here - just not as an instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry - I misinterpreted the response to the issue. I've removed the instance declaration from that module.

@jamesmckinna
Copy link
Contributor

You'll also need CHANGELOG entries to record the additions...

@rvs314 rvs314 requested a review from JacquesCarette July 1, 2025 20:42
@rvs314
Copy link
Contributor Author

rvs314 commented Jul 1, 2025

You'll also need CHANGELOG entries to record the additions...

Thanks for catching this. I've added the change under "Minor Improvements".

@jamesmckinna
Copy link
Contributor

You'll also need CHANGELOG entries to record the additions...

Thanks for catching this. I've added the change under "Minor Improvements".

Actually: you need to do this under Additions to existing modules... Sorry not to have been more explicit ;-)

@rvs314 rvs314 force-pushed the list-literal-instances branch from 962b5a4 to 80a9979 Compare July 1, 2025 20:56
@rvs314
Copy link
Contributor Author

rvs314 commented Jul 1, 2025

Actually: you need to do this under Additions to existing modules... Sorry not to have been more explicit ;-)

No worries; I just amended the commit.

@JacquesCarette
Copy link
Contributor

There's a whitespace problem that will need fixed.

@rvs314
Copy link
Contributor Author

rvs314 commented Jul 2, 2025

Sorry, didn't see that! It should be fixed now (or, at least, the tool gives no complaints)

@jamesmckinna
Copy link
Contributor

For some reason, your example at the top of not having tt in scope didn't display?

I was curious to look at it, not least because my (probably faulty!) impression is that no explicit use of tt need ever appear in stdlib, because it is uniquely inferrable (as the single constructor of a record with eta) from _. And that it's thus inferrable even when Data.Unit.Base.⊤ has not explicitly been brought into scope (this is perhaps where I'm mistaken?). Happy to be corrected on this!

@jamesmckinna
Copy link
Contributor

I'm happy to take this off the docket and merge it now for v2.3,unless there are violent objections!?

@jamesmckinna jamesmckinna modified the milestones: v2.4, v2.3 Jul 16, 2025
@MatthewDaggitt MatthewDaggitt added this pull request to the merge queue Jul 17, 2025
Merged via the queue into agda:master with commit eef9345 Jul 17, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IsString typeclass isn't actually listed as an instance in Data.List.Literals
5 participants