Add Show class - #3098
Conversation
|
#569 added Although, I'm not strongly opinionated to either direction. |
JacquesCarette
left a comment
There was a problem hiding this comment.
Comments on just the code.
| module Text.Show where | ||
|
|
||
| -- should builtin be used? | ||
| open import Agda.Builtin.Reflection using (Precedence) |
There was a problem hiding this comment.
You should avoid directly using builtins. Normally there is something in the library that re-exports it. There's a whole Reflection sub-library, it is likely there?
There was a problem hiding this comment.
It doesn't re-export Precedence from what I can tell (using rgrep)
|
Re: macros for deriving instances. 1) very good thing to offer. 2) likely we won't use them internally, as they do evil things to the dependency graph. Also, one thing Haskell got "wrong" was that |
As in what is IMO doing the |
|
Re: |
|
Definitely not an expert, at least from my end! Other than |
MatthewDaggitt
left a comment
There was a problem hiding this comment.
I'm happy with the names Show, Pretty, Read, Write
|
|
||
| instance | ||
| ListShow : {{ Show A }} → Show (List A) | ||
| ListShow .showsPrecList prec [] str = '[' ∷ (']' ∷ str) |
There was a problem hiding this comment.
We should probably define a surround and a concatenate in the library if we don't already have those and define this in terms of them?
|
Thoughts on the given interfaces? Still not entirely sure how to go about having properties that Read and Write work together, and I'm not fully happy with the |
| private | ||
| test[ℕ] : String | ||
| test[ℕ] = write (5 ∷ 2 ∷ 12 ∷ 42 ∷ []) |
There was a problem hiding this comment.
We may as well make this a unit test?
_ : write (5 ∷ 2 ∷ 12 ∷ 42 ∷ []) ≡ ?
_ = refl
(with the ? appropriately filled in)
|
|
||
| record Read (A : Set a) : Set a where | ||
| field | ||
| read : String → Maybe A |
There was a problem hiding this comment.
Should this be a derived operation based on a more general String -> Maybe (a, String)?
Or even List rather than Maybe? Maybe even one with a precedence?
Cf. https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Prelude.html#v:readsPrec
There was a problem hiding this comment.
Why would you use List instead of Maybe?
|
RE: "ReadWrite", I'm somewhat coming around to having the proof in a separate, combined record. In that it is most likely a specific pair of Anything else seems like it would
I could be overthinking this, however. |
|
|
Should hopefully resolve #569 and partially address #431.
Opening as a draft to start discussion on design. Points to look into:
ParseorReadclass that does the inverse