Skip to content

Commit

Permalink
Merge pull request purescript#18 from purescript/bump
Browse files Browse the repository at this point in the history
Prepare for 2.0 release
  • Loading branch information
garyb authored Oct 9, 2016
2 parents 5f584f2 + 38a655c commit c3cd333
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
10 changes: 5 additions & 5 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
"package.json"
],
"dependencies": {
"purescript-either": "^1.0.0",
"purescript-strings": "^1.0.0",
"purescript-unfoldable": "^1.0.0"
"purescript-either": "^2.0.0",
"purescript-strings": "^2.0.0",
"purescript-unfoldable": "^2.0.0"
},
"devDependencies": {
"purescript-assert": "^1.0.0",
"purescript-console": "^1.0.0"
"purescript-assert": "^2.0.0",
"purescript-console": "^2.0.0"
}
}
22 changes: 13 additions & 9 deletions src/Data/Enum.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Data.Enum
, enumFromThenTo
, upFrom
, downFrom
, Cardinality(..), runCardinality
, Cardinality(..)
, class BoundedEnum, cardinality, toEnum, fromEnum, toEnumWithDefaults
, defaultCardinality
, defaultToEnum
Expand All @@ -20,15 +20,19 @@ import Control.MonadPlus (guard)
import Data.Char (fromCharCode, toCharCode)
import Data.Either (Either(..))
import Data.Maybe (Maybe(..), maybe, fromJust)
import Data.Newtype (class Newtype, unwrap)
import Data.Tuple (Tuple(..))
import Data.Unfoldable (class Unfoldable, unfoldr)

import Partial.Unsafe (unsafePartial)

newtype Cardinality a = Cardinality Int

runCardinality :: forall a. Cardinality a -> Int
runCardinality (Cardinality a) = a
derive instance newtypeCardinality :: Newtype (Cardinality a) _

derive newtype instance eqCardinality :: Eq (Cardinality a)

derive newtype instance ordCardinality :: Ord (Cardinality a)

-- | Type class for enumerations.
-- |
Expand Down Expand Up @@ -188,7 +192,7 @@ instance boundedEnumOrdering :: BoundedEnum Ordering where
fromEnum GT = 2

instance boundedEnumMaybe :: BoundedEnum a => BoundedEnum (Maybe a) where
cardinality = Cardinality $ runCardinality (cardinality :: Cardinality a) + 1
cardinality = Cardinality $ unwrap (cardinality :: Cardinality a) + 1
toEnum = to cardinality
where
to :: Cardinality a -> Int -> Maybe (Maybe a)
Expand All @@ -201,8 +205,8 @@ instance boundedEnumMaybe :: BoundedEnum a => BoundedEnum (Maybe a) where
instance boundedEnumEither :: (BoundedEnum a, BoundedEnum b) => BoundedEnum (Either a b) where
cardinality =
Cardinality
$ runCardinality (cardinality :: Cardinality a)
+ runCardinality (cardinality :: Cardinality b)
$ unwrap (cardinality :: Cardinality a)
+ unwrap (cardinality :: Cardinality b)
toEnum = to cardinality cardinality
where
to :: Cardinality a -> Cardinality (Either a b) -> Int -> Maybe (Either a b)
Expand All @@ -211,13 +215,13 @@ instance boundedEnumEither :: (BoundedEnum a, BoundedEnum b) => BoundedEnum (Eit
| n >= ca && n < cab = Right <$> toEnum (n - ca)
| otherwise = Nothing
fromEnum (Left a) = fromEnum a
fromEnum (Right b) = fromEnum b + runCardinality (cardinality :: Cardinality a)
fromEnum (Right b) = fromEnum b + unwrap (cardinality :: Cardinality a)

instance boundedEnumTuple :: (BoundedEnum a, BoundedEnum b) => BoundedEnum (Tuple a b) where
cardinality =
Cardinality
$ runCardinality (cardinality :: Cardinality a)
* runCardinality (cardinality :: Cardinality b)
$ unwrap (cardinality :: Cardinality a)
* unwrap (cardinality :: Cardinality b)
toEnum = to cardinality
where
to :: Cardinality b -> Int -> Maybe (Tuple a b)
Expand Down

0 comments on commit c3cd333

Please sign in to comment.