Skip to content
This repository was archived by the owner on Mar 25, 2021. It is now read-only.
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/bower_components/
/node_modules/
/output/
package-lock.json
26 changes: 26 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright 2018 PureScript

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 changes: 19 additions & 14 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
{
"name": "purescript-generics-rep",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"output"
],
"license": "MIT",
"homepage": "https://github.com/purescript/purescript-generics-rep",
"license": "BSD-3-Clause",
"repository": {
"type": "git",
"url": "git://github.com/purescript/purescript-generics-rep.git"
},
"ignore": [
"**/.*",
"bower_components",
"node_modules",
"output",
"test",
"bower.json",
"gulpfile.js",
"package.json"
],
"dependencies": {
"purescript-enums": "^3.2.1",
"purescript-foldable-traversable": "^3.0.0",
"purescript-monoid": "^3.0.0",
"purescript-prelude": "^3.0.0",
"purescript-symbols": "^3.0.0"
"purescript-enums": "^4.0.0",
"purescript-foldable-traversable": "^4.0.0",
"purescript-maybe": "^4.0.0",
"purescript-newtype": "^3.0.0",
"purescript-prelude": "^4.0.0"
},
"devDependencies": {
"purescript-assert": "^3.0.0",
"purescript-console": "^3.0.0"
"purescript-assert": "^4.0.0",
"purescript-console": "^4.0.0"
}
}
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"scripts": {
"clean": "rimraf output && rimraf .pulp-cache",
"build": "eslint src && pulp build -- --censor-lib --strict",
"test": "pulp test"
"test": "pulp test --check-main-type Effect.Effect"
},
"devDependencies": {
"eslint": "^3.17.1",
"pulp": "^10.0.4",
"purescript-psa": "^0.5.0-rc.1",
"rimraf": "^2.6.1"
"eslint": "^4.19.1",
"pulp": "^12.2.0",
"purescript-psa": "^0.6.0",
"rimraf": "^2.6.2"
}
}
9 changes: 0 additions & 9 deletions src/Data/Generic/Rep.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ module Data.Generic.Rep
, Product(..)
, Constructor(..)
, Argument(..)
, Rec(..)
, Field(..)
) where

import Data.Maybe (Maybe(..))
Expand All @@ -33,13 +31,6 @@ newtype Constructor (name :: Symbol) a = Constructor a
-- | A representation for an argument in a data constructor.
newtype Argument a = Argument a

-- | A representation for records.
newtype Rec fields = Rec fields

-- | A representation for a record field which includes the field name
-- | as a type-level string.
newtype Field (field :: Symbol) a = Field a

-- | The `Generic` class asserts the existence of a type function from types
-- | to their representations using the type constructors defined in this module.
class Generic a rep | a -> rep where
Expand Down
6 changes: 0 additions & 6 deletions src/Data/Generic/Rep/Eq.purs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ instance genericEqConstructor :: GenericEq a => GenericEq (Constructor name a) w
instance genericEqArgument :: Eq a => GenericEq (Argument a) where
genericEq' (Argument a1) (Argument a2) = a1 == a2

instance genericEqRec :: GenericEq a => GenericEq (Rec a) where
genericEq' (Rec a1) (Rec a2) = genericEq' a1 a2

instance genericEqField :: Eq a => GenericEq (Field name a) where
genericEq' (Field a1) (Field a2) = a1 == a2

-- | A `Generic` implementation of the `eq` member from the `Eq` type class.
genericEq :: forall a rep. Generic a rep => GenericEq rep => a -> a -> Boolean
genericEq x y = genericEq' (from x) (from y)
6 changes: 0 additions & 6 deletions src/Data/Generic/Rep/Monoid.purs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ instance genericMonoidConstructor :: GenericMonoid a => GenericMonoid (Construct
instance genericMonoidArgument :: Monoid a => GenericMonoid (Argument a) where
genericMempty' = Argument mempty

instance genericMonoidRec :: GenericMonoid a => GenericMonoid (Rec a) where
genericMempty' = Rec genericMempty'

instance genericMonoidField :: Monoid a => GenericMonoid (Field name a) where
genericMempty' = Field mempty

-- | A `Generic` implementation of the `mempty` member from the `Monoid` type class.
genericMempty :: forall a rep. Generic a rep => GenericMonoid rep => a
genericMempty = to genericMempty'
6 changes: 0 additions & 6 deletions src/Data/Generic/Rep/Ord.purs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ instance genericOrdConstructor :: GenericOrd a => GenericOrd (Constructor name a
instance genericOrdArgument :: Ord a => GenericOrd (Argument a) where
genericCompare' (Argument a1) (Argument a2) = compare a1 a2

instance genericOrdRec :: GenericOrd a => GenericOrd (Rec a) where
genericCompare' (Rec a1) (Rec a2) = genericCompare' a1 a2

instance genericOrdField :: Ord a => GenericOrd (Field name a) where
genericCompare' (Field a1) (Field a2) = compare a1 a2

-- | A `Generic` implementation of the `compare` member from the `Ord` type class.
genericCompare :: forall a rep. Generic a rep => GenericOrd rep => a -> a -> Ordering
genericCompare x y = genericCompare' (from x) (from y)
6 changes: 0 additions & 6 deletions src/Data/Generic/Rep/Semigroup.purs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ instance genericSemigroupConstructor :: GenericSemigroup a => GenericSemigroup (
instance genericSemigroupArgument :: Semigroup a => GenericSemigroup (Argument a) where
genericAppend' (Argument a1) (Argument a2) = Argument (append a1 a2)

instance genericSemigroupRec :: GenericSemigroup a => GenericSemigroup (Rec a) where
genericAppend' (Rec a1) (Rec a2) = Rec (genericAppend' a1 a2)

instance genericSemigroupField :: Semigroup a => GenericSemigroup (Field name a) where
genericAppend' (Field a1) (Field a2) = Field (append a1 a2)

-- | A `Generic` implementation of the `append` member from the `Semigroup` type class.
genericAppend :: forall a rep. Generic a rep => GenericSemigroup rep => a -> a -> a
genericAppend x y = to (genericAppend' (from x) (from y))
22 changes: 0 additions & 22 deletions src/Data/Generic/Rep/Show.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ module Data.Generic.Rep.Show
, genericShow
, class GenericShowArgs
, genericShowArgs
, class GenericShowFields
, genericShowFields
) where

import Prelude (class Show, show, (<>))
Expand All @@ -19,9 +17,6 @@ class GenericShow a where
class GenericShowArgs a where
genericShowArgs :: a -> Array String

class GenericShowFields a where
genericShowFields :: a -> Array String

instance genericShowNoConstructors :: GenericShow NoConstructors where
genericShow' a = genericShow' a

Expand All @@ -37,11 +32,6 @@ instance genericShowArgsProduct
=> GenericShowArgs (Product a b) where
genericShowArgs (Product a b) = genericShowArgs a <> genericShowArgs b

instance genericShowFieldsProduct
:: (GenericShowFields a, GenericShowFields b)
=> GenericShowFields (Product a b) where
genericShowFields (Product a b) = genericShowFields a <> genericShowFields b

instance genericShowConstructor
:: (GenericShowArgs a, IsSymbol name)
=> GenericShow (Constructor name a) where
Expand All @@ -56,18 +46,6 @@ instance genericShowConstructor
instance genericShowArgsArgument :: Show a => GenericShowArgs (Argument a) where
genericShowArgs (Argument a) = [show a]

instance genericShowArgsRec :: GenericShowFields a => GenericShowArgs (Rec a) where
genericShowArgs (Rec a) = ["{ " <> intercalate ", " (genericShowFields a) <> " }"]

instance genericShowFieldsField
:: (Show a, IsSymbol name)
=> GenericShowFields (Field name a) where
genericShowFields (Field a) =
[reflectSymbol (SProxy :: SProxy name) <> ": " <> show a]

instance genericShowFieldsNoArguments :: GenericShowFields NoArguments where
genericShowFields _ = []

-- | A `Generic` implementation of the `show` member from the `Show` type class.
genericShow :: forall a rep. Generic a rep => GenericShow rep => a -> String
genericShow x = genericShow' (from x)
20 changes: 8 additions & 12 deletions test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module Test.Main where

import Prelude

import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log, logShow)
import Effect (Effect)
import Effect.Console (log, logShow)
import Data.Enum (class BoundedEnum, class Enum, Cardinality(..), cardinality, fromEnum, pred, succ, toEnum, enumFromTo)
import Data.Generic.Rep as G
import Data.Generic.Rep.Bounded as GBounded
Expand All @@ -12,7 +12,7 @@ import Data.Generic.Rep.Eq as GEq
import Data.Generic.Rep.Ord as GOrd
import Data.Generic.Rep.Show as GShow
import Data.Maybe (Maybe(..))
import Test.Assert (ASSERT, assert)
import Test.Assert (assert)

data List a = Nil | Cons { head :: a, tail :: List a }

Expand All @@ -24,9 +24,6 @@ derive instance genericList :: G.Generic (List a) _
instance eqList :: Eq a => Eq (List a) where
eq x y = GEq.genericEq x y

instance ordList :: Ord a => Ord (List a) where
compare x y = GOrd.genericCompare x y

instance showList :: Show a => Show (List a) where
show x = GShow.genericShow x

Expand Down Expand Up @@ -105,9 +102,8 @@ instance boundedEnumPair :: (BoundedEnum a, BoundedEnum b) => BoundedEnum (Pair
cardinality = GEnum.genericCardinality
toEnum = GEnum.genericToEnum
fromEnum = GEnum.genericFromEnum


main :: Eff (console :: CONSOLE, assert :: ASSERT) Unit
main :: Effect Unit
main = do
logShow (cons 1 (cons 2 Nil))

Expand All @@ -118,13 +114,13 @@ main = do
assert $ cons 1 (cons 2 Nil) /= cons 1 Nil

log "Checking comparison EQ"
assert $ (cons 1 (cons 2 Nil) `compare` cons 1 (cons 2 Nil)) == EQ
assert $ (Pair Zero (Some One) `compare` Pair Zero (Some One)) == EQ

log "Checking comparison GT"
assert $ (cons 1 (cons 2 Nil) `compare` cons 1 Nil) == GT
assert $ (Pair (Some One) Zero `compare` Pair (Some Zero) Zero) == GT

log "Checking comparison LT"
assert $ (cons 1 Nil `compare` cons 1 (cons 2 Nil)) == LT
assert $ (Pair Zero One `compare` Pair One One) == LT

log "Checking simple bottom"
assert $ bottom == A
Expand Down Expand Up @@ -199,4 +195,4 @@ main = do

log "Checking product toEnum/fromEnum roundtrip"
assert $ let allPairs = enumFromTo bottom top :: Array (Pair Bit SimpleBounded)
in toEnum <<< fromEnum <$> allPairs == Just <$> allPairs
in (toEnum <<< fromEnum <$> allPairs) == (Just <$> allPairs)