Skip to content
This repository was archived by the owner on Mar 25, 2021. It is now read-only.

Add Show instances for the Rep types #11

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"purescript-foldable-traversable": "^3.0.0"
},
"devDependencies": {
"purescript-console": "^3.0.0"
"purescript-console": "^3.0.0",
"purescript-psci-support": "^3.0.0"
}
}
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{
"private": true,
"scripts": {
"install": "rimraf bower_components && bower install",
"clean": "rimraf output && rimraf .pulp-cache",
"build": "eslint src && pulp build -- --censor-lib --strict",
"test": "pulp test"
"test": "pulp test",
"pulp": "pulp"
},
"devDependencies": {
"bower": "^1.8.0",
"eslint": "^3.17.1",
"pulp": "^10.0.4",
"pulp": "^11.0.0",
"purescript": "^0.11.5",
"purescript-psa": "^0.5.0-rc.1",
"rimraf": "^2.6.1"
}
Expand Down
23 changes: 23 additions & 0 deletions src/Data/Generic/Rep.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 " <> show (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 " <> show (reflectSymbol (SProxy :: SProxy name)) <> " " <> show a <> ")"
2 changes: 2 additions & 0 deletions test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ main = do

logShow (bottom :: SimpleBounded)
logShow (top :: SimpleBounded)

logShow (G.from $ cons 1 Nil)