-
Notifications
You must be signed in to change notification settings - Fork 272
Add Show class
#3098
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
Draft
silas-hw
wants to merge
23
commits into
agda:master
Choose a base branch
from
silas-hw:show
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Add Show class
#3098
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
d01fd7f
Add show class
silas-hw 32907ba
Cleanup code
silas-hw 8776f8e
Cleanup code
silas-hw befbdf1
Move List Show instance to .Instances module
silas-hw e762d27
Move instances to .Instances modules for Nat and Integer
silas-hw 4c8232d
Rename Show to Write
silas-hw c9d932a
Introduce Pretty, Write, Read, and ReadWrite
silas-hw a6496e1
Fix IntWrite
silas-hw fa521f3
Remove accidental indent in Data.List.Instances
silas-hw 5986b9e
Fix typo
silas-hw 335dd51
Update Read interface
silas-hw 892fd98
Fix whitespace
silas-hw fe50044
Add Maybe Pretty instance
silas-hw b7823a0
Add 'pretty' function to Pretty
silas-hw 2c7c8af
Add NatPretty instance
silas-hw fec6ee2
Add module header
silas-hw b96a6a9
Fix whitespace
silas-hw 87d7f8f
Add modules to unsafe and withK sets in GenerateEverything
silas-hw 35b27c2
Add NatRead instance
silas-hw 8d97b80
Rename variables
silas-hw 0187201
Start on deriving macro
silas-hw 16f0741
[skip ci] Add note
silas-hw 876fc3c
[skip ci] Add more stub methods to Write.Deriving and experiment with…
silas-hw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| ------------------------------------------------------------------------ | ||
| -- The Agda standard library | ||
| -- | ||
| -- Unsafe instances for List | ||
| ------------------------------------------------------------------------ | ||
|
|
||
| {-# OPTIONS --with-K #-} | ||
|
|
||
| module Data.List.Unsafe.Instances where | ||
|
|
||
| open import Data.List.Base | ||
| open import Data.Nat.Base | ||
| open import Data.Nat.Instances | ||
| open import Level using (Level) | ||
| open import Text.Write | ||
| open import Text.Pretty 80 | ||
|
|
||
| private | ||
| variable | ||
| a : Level | ||
| A : Set a | ||
|
|
||
| open Pretty {{...}} | ||
|
|
||
| instance | ||
| ListPretty : {{ Pretty A }} → Pretty (List A) | ||
| ListPretty .pPrintPrec prec xs = parens (commaSep (map (pPrintPrec prec) xs)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| ------------------------------------------------------------------------ | ||
| -- The Agda standard library | ||
| -- | ||
| -- Unsafe instances for Maybe | ||
| ------------------------------------------------------------------------ | ||
|
|
||
| {-# OPTIONS --with-K #-} | ||
|
|
||
| module Data.Maybe.Unsafe.Instances where | ||
|
|
||
| open import Data.Maybe.Base | ||
| open import Text.Pretty 80 | ||
| open import Level using (Level) | ||
|
|
||
| private | ||
| variable | ||
| a : Level | ||
| A : Set a | ||
|
|
||
| instance | ||
| open Pretty {{...}} | ||
| MaybePretty : {{ Pretty A }} → Pretty (Maybe A) | ||
| MaybePretty .pPrintPrec prec (just x) = (text "just") <+> pPrintPrec prec x | ||
| MaybePretty .pPrintPrec prec nothing = text "nothing" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| ------------------------------------------------------------------------ | ||
| -- The Agda standard library | ||
| -- | ||
| -- Unsafe instances for Nat | ||
| ------------------------------------------------------------------------ | ||
|
|
||
| {-# OPTIONS --with-K #-} | ||
|
|
||
| module Data.Nat.Unsafe.Instances where | ||
|
|
||
| open import Data.Nat.Base | ||
| open import Data.Nat.Show using (show) | ||
| open import Text.Pretty 80 | ||
|
|
||
| instance | ||
| open Pretty {{...}} | ||
| ℕPretty : Pretty ℕ | ||
| ℕPretty .pPrintPrec prec n = text (show n) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| ------------------------------------------------------------------------ | ||
| -- The Agda standard library | ||
| -- | ||
| -- Read class | ||
| ------------------------------------------------------------------------ | ||
|
|
||
| {-# OPTIONS --without-K --safe #-} | ||
|
|
||
| module Text.Read where | ||
|
|
||
| -- should builtin be used? | ||
| open import Agda.Builtin.Reflection using (Precedence) public | ||
| open import Data.Char.Base using (Char) public | ||
| open import Data.List.Base using (List; []; _++_; _∷_) | ||
| open import Data.Maybe.Base using (Maybe; just; nothing; map) | ||
| open import Data.Product.Base using (_×_; _,_; proj₁) renaming (map to map×) | ||
| open import Data.String.Base using (String) public | ||
| open import Data.String.Base using (fromList; toList) | ||
| open import Function.Base using (_∘_; const; _$_; id) | ||
| open import Level using (Level) | ||
|
|
||
| private | ||
| variable | ||
| a : Level | ||
| A : Set a | ||
|
|
||
| record Read (A : Set a) : Set a where | ||
| field | ||
| readsPrecList : Precedence → List Char → Maybe (A × List Char) | ||
|
|
||
| readPrecList : Precedence → List Char → Maybe A | ||
| readPrecList prec str = map proj₁ (readsPrecList prec str) | ||
|
|
||
| readsPrec : Precedence → String → Maybe (A × String) | ||
| readsPrec prec str = map (map× id fromList) (readsPrecList prec (toList str)) | ||
|
|
||
| readPrec : Precedence → String → Maybe A | ||
| readPrec prec = (readPrecList prec) ∘ toList | ||
|
|
||
| read : String → Maybe A | ||
| read = readPrec Precedence.unrelated |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| ------------------------------------------------------------------------ | ||
| -- The Agda standard library | ||
| -- | ||
| -- ReadWrite class | ||
| ------------------------------------------------------------------------ | ||
|
|
||
| {-# OPTIONS --without-K --safe #-} | ||
|
|
||
| module Text.ReadWrite where | ||
|
|
||
| -- should builtin be used? | ||
| open import Agda.Builtin.Reflection using (Precedence) public | ||
| open import Data.Char.Base using (Char) public | ||
| open import Data.List.Base using (List; []; _++_; _∷_) | ||
| open import Data.Nat.Show using () renaming (show to showℕ) | ||
| open import Data.Maybe.Base using (just) | ||
| open import Data.String.Base using (String) public | ||
| open import Data.String.Base using (fromList; toList) | ||
| open import Function.Base using (_∘_; const; _$_) | ||
| open import Level using (Level) | ||
| open import Relation.Binary.PropositionalEquality using (_≡_) | ||
| open import Text.Write using (Write) | ||
| open import Text.Read using (Read) | ||
|
|
||
| private | ||
| variable | ||
| a : Level | ||
| A : Set a | ||
|
|
||
| record ReadWrite (A : Set a) : Set a where | ||
| open Read | ||
| open Write | ||
|
|
||
| field | ||
| reader : Read A | ||
| writer : Write A | ||
|
|
||
| readWrite : ∀ {x : A} → read reader (write writer x) ≡ (just x) | ||
| writeRead : ∀ {x : A} {s : String} → (read reader s) ≡ (just x) → writeMaybe writer (read reader s) ≡ s | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| ------------------------------------------------------------------------ | ||
| -- The Agda standard library | ||
| -- | ||
| -- Write class | ||
| ------------------------------------------------------------------------ | ||
|
|
||
| {-# OPTIONS --without-K --safe #-} | ||
|
|
||
| module Text.Write where | ||
|
|
||
| -- should builtin be used? | ||
| open import Agda.Builtin.Reflection using (Precedence) public | ||
| open import Data.Char.Base using (Char) public | ||
| open import Data.List.Base using (List; []; _++_; _∷_) | ||
| open import Data.Maybe.Base using (Maybe; just; nothing) | ||
| open import Data.Nat.Show using () renaming (show to showℕ) | ||
| open import Data.String.Base using (String) public | ||
| open import Data.String.Base using (fromList; toList) | ||
| open import Function.Base using (_∘_; const; _$_) | ||
| open import Level using (Level) | ||
|
|
||
| private | ||
| variable | ||
| a : Level | ||
| A : Set a | ||
|
|
||
| record Write (A : Set a) : Set a where | ||
| field | ||
| writesPrecList : Precedence → A → List Char → List Char | ||
|
|
||
| writePrecList : Precedence → A → List Char | ||
| writePrecList prec x = writesPrecList prec x [] | ||
|
|
||
| writesPrec : Precedence → A → String → String | ||
| writesPrec prec x str = fromList (writesPrecList prec x (toList str)) | ||
|
|
||
| writePrec : Precedence → A → String | ||
| writePrec prec x = fromList (writesPrecList prec x []) | ||
|
|
||
| write : A → String | ||
| write = writePrec Precedence.unrelated | ||
|
|
||
| writeMaybe : Maybe A → String | ||
| writeMaybe nothing = "" | ||
| writeMaybe (just x) = write x |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may as well make this a unit test?
(with the
?appropriately filled in)