This repository was archived by the owner on Mar 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Add Show instances for the Rep types #11
Closed
daniel-chambers
wants to merge
4
commits into
purescript-deprecated:master
from
daniel-chambers:show-reps
Closed
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fd76f10
Add Show instances for the Rep types
daniel-chambers a3d1857
psci dev dependency
daniel-chambers 251e77a
Added missing deps and install script. Also bumped pulp since it seem…
daniel-chambers 57e0a12
Use the Show instance for the constructor and field names
daniel-chambers 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,9 @@ module Data.Generic.Rep | |
, Field(..) | ||
) where | ||
|
||
import Prelude | ||
import Data.Maybe (Maybe(..)) | ||
import Data.Symbol (class IsSymbol, SProxy(..), reflectSymbol) | ||
|
||
-- | A representation for types with no constructors. | ||
data NoConstructors | ||
|
@@ -55,3 +57,24 @@ instance genericMaybe | |
from Nothing = Inl (Constructor NoArguments) | ||
from (Just a) = Inr (Constructor (Argument a)) | ||
|
||
instance showNoArguments :: Show NoArguments where | ||
show _ = "NoArguments" | ||
|
||
instance showSum :: (Show a, Show b) => Show (Sum a b) where | ||
show (Inl a) = "(Inl " <> show a <> ")" | ||
show (Inr b) = "(Inr " <> show b <> ")" | ||
|
||
instance showProduct :: (Show a, Show b) => Show (Product a b) where | ||
show (Product a b) = "(Product " <> show a <> " " <> show b <> ")" | ||
|
||
instance showConstructor :: (IsSymbol name, Show a) => Show (Constructor name a) where | ||
show (Constructor a) = "(Constructor \"" <> reflectSymbol (SProxy :: SProxy name) <> "\" " <> show a <> ")" | ||
|
||
instance showArgument :: Show a => Show (Argument a) where | ||
show (Argument a) = "(Argument " <> show a <> ")" | ||
|
||
instance showRec :: Show a => Show (Rec a) where | ||
show (Rec a) = "(Rec " <> show a <> ")" | ||
|
||
instance showField :: (IsSymbol name, Show a) => Show (Field name a) where | ||
show (Field a) = "(Field \"" <> reflectSymbol (SProxy :: SProxy name) <> "\" " <> show a <> ")" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here please |
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 |
---|---|---|
|
@@ -49,3 +49,5 @@ main = do | |
|
||
logShow (bottom :: SimpleBounded) | ||
logShow (top :: SimpleBounded) | ||
|
||
logShow (G.from $ cons 1 Nil) |
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.
Let's use
show
on the string here, instead of wrapping in quotes, since it might need escaping.