prelude-safeenum 0.1.1.2 → 0.1.1.3
raw patch · 6 files changed
+95/−88 lines, 6 filesdep ~basenew-uploaderPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: base
API changes (from Hackage documentation)
- Data.Number.CalkinWilf: instance (Integral a, Read a) => Read (CalkinWilf a)
- Data.Number.CalkinWilf: instance (Integral a, Show a) => Show (CalkinWilf a)
- Data.Number.CalkinWilf: instance Eq a => Eq (CalkinWilf a)
- Data.Number.CalkinWilf: instance Integral a => DownwardEnum (CalkinWilf a)
- Data.Number.CalkinWilf: instance Integral a => Enum (CalkinWilf a)
- Data.Number.CalkinWilf: instance Integral a => Fractional (CalkinWilf a)
- Data.Number.CalkinWilf: instance Integral a => Num (CalkinWilf a)
- Data.Number.CalkinWilf: instance Integral a => Ord (CalkinWilf a)
- Data.Number.CalkinWilf: instance Integral a => Real (CalkinWilf a)
- Data.Number.CalkinWilf: instance Integral a => RealFrac (CalkinWilf a)
- Data.Number.CalkinWilf: instance Integral a => UpwardEnum (CalkinWilf a)
- Prelude.SafeEnum: instance DownwardEnum ()
- Prelude.SafeEnum: instance DownwardEnum Bool
- Prelude.SafeEnum: instance DownwardEnum Char
- Prelude.SafeEnum: instance DownwardEnum Int
- Prelude.SafeEnum: instance DownwardEnum Integer
- Prelude.SafeEnum: instance DownwardEnum Ordering
- Prelude.SafeEnum: instance Enum ()
- Prelude.SafeEnum: instance Enum Bool
- Prelude.SafeEnum: instance Enum Char
- Prelude.SafeEnum: instance Enum Int
- Prelude.SafeEnum: instance Enum Integer
- Prelude.SafeEnum: instance Enum Ordering
- Prelude.SafeEnum: instance UpwardEnum ()
- Prelude.SafeEnum: instance UpwardEnum Bool
- Prelude.SafeEnum: instance UpwardEnum Char
- Prelude.SafeEnum: instance UpwardEnum Int
- Prelude.SafeEnum: instance UpwardEnum Integer
- Prelude.SafeEnum: instance UpwardEnum Ordering
+ Data.Number.CalkinWilf: instance (GHC.Real.Integral a, GHC.Read.Read a) => GHC.Read.Read (Data.Number.CalkinWilf.CalkinWilf a)
+ Data.Number.CalkinWilf: instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.Number.CalkinWilf.CalkinWilf a)
+ Data.Number.CalkinWilf: instance GHC.Real.Integral a => GHC.Classes.Ord (Data.Number.CalkinWilf.CalkinWilf a)
+ Data.Number.CalkinWilf: instance GHC.Real.Integral a => GHC.Enum.Enum (Data.Number.CalkinWilf.CalkinWilf a)
+ Data.Number.CalkinWilf: instance GHC.Real.Integral a => GHC.Num.Num (Data.Number.CalkinWilf.CalkinWilf a)
+ Data.Number.CalkinWilf: instance GHC.Real.Integral a => GHC.Real.Fractional (Data.Number.CalkinWilf.CalkinWilf a)
+ Data.Number.CalkinWilf: instance GHC.Real.Integral a => GHC.Real.Real (Data.Number.CalkinWilf.CalkinWilf a)
+ Data.Number.CalkinWilf: instance GHC.Real.Integral a => GHC.Real.RealFrac (Data.Number.CalkinWilf.CalkinWilf a)
+ Data.Number.CalkinWilf: instance GHC.Real.Integral a => Prelude.SafeEnum.DownwardEnum (Data.Number.CalkinWilf.CalkinWilf a)
+ Data.Number.CalkinWilf: instance GHC.Real.Integral a => Prelude.SafeEnum.Enum (Data.Number.CalkinWilf.CalkinWilf a)
+ Data.Number.CalkinWilf: instance GHC.Real.Integral a => Prelude.SafeEnum.UpwardEnum (Data.Number.CalkinWilf.CalkinWilf a)
+ Data.Number.CalkinWilf: instance GHC.Show.Show a => GHC.Show.Show (Data.Number.CalkinWilf.CalkinWilf a)
+ Prelude.SafeEnum: infix 4 `precedes`
+ Prelude.SafeEnum: instance Prelude.SafeEnum.DownwardEnum ()
+ Prelude.SafeEnum: instance Prelude.SafeEnum.DownwardEnum GHC.Integer.Type.Integer
+ Prelude.SafeEnum: instance Prelude.SafeEnum.DownwardEnum GHC.Types.Bool
+ Prelude.SafeEnum: instance Prelude.SafeEnum.DownwardEnum GHC.Types.Char
+ Prelude.SafeEnum: instance Prelude.SafeEnum.DownwardEnum GHC.Types.Int
+ Prelude.SafeEnum: instance Prelude.SafeEnum.DownwardEnum GHC.Types.Ordering
+ Prelude.SafeEnum: instance Prelude.SafeEnum.Enum ()
+ Prelude.SafeEnum: instance Prelude.SafeEnum.Enum GHC.Integer.Type.Integer
+ Prelude.SafeEnum: instance Prelude.SafeEnum.Enum GHC.Types.Bool
+ Prelude.SafeEnum: instance Prelude.SafeEnum.Enum GHC.Types.Char
+ Prelude.SafeEnum: instance Prelude.SafeEnum.Enum GHC.Types.Int
+ Prelude.SafeEnum: instance Prelude.SafeEnum.Enum GHC.Types.Ordering
+ Prelude.SafeEnum: instance Prelude.SafeEnum.UpwardEnum ()
+ Prelude.SafeEnum: instance Prelude.SafeEnum.UpwardEnum GHC.Integer.Type.Integer
+ Prelude.SafeEnum: instance Prelude.SafeEnum.UpwardEnum GHC.Types.Bool
+ Prelude.SafeEnum: instance Prelude.SafeEnum.UpwardEnum GHC.Types.Char
+ Prelude.SafeEnum: instance Prelude.SafeEnum.UpwardEnum GHC.Types.Int
+ Prelude.SafeEnum: instance Prelude.SafeEnum.UpwardEnum GHC.Types.Ordering
- Data.Number.CalkinWilf: CalkinWilf :: (Ratio a) -> CalkinWilf a
+ Data.Number.CalkinWilf: CalkinWilf :: Ratio a -> CalkinWilf a
- Prelude.SafeEnum: class DownwardEnum a where enumDownFrom x0 = build (enumDownFromFB x0) where {-# INLINE[0] enumDownFromFB #-} enumDownFromFB x cons nil = x `cons` case pred x of { Nothing -> nil Just y -> enumDownFromFB y cons nil } enumDownFromTo x0 z0 = build (enumDownFromToFB x0 z0) where {-# INLINE[0] enumDownFromToFB #-} enumDownFromToFB x z cons nil | x `precedes` z = nil | otherwise = x `cons` case pred x of { Nothing -> nil Just y -> enumDownFromToFB y z cons nil }
+ Prelude.SafeEnum: class DownwardEnum a
- Prelude.SafeEnum: class (UpwardEnum a, DownwardEnum a) => Enum a where enumFromThen x y = maybe [x] id $! do { x' <- fromEnum x; y' <- fromEnum y; return $! takeEnum (enumFromThen x' y') } enumFromThenTo x y z | x `precedes` y && x `succeeds` z = [] | x `succeeds` y && x `precedes` z = [] | otherwise = maybe [x] id $! do { x' <- fromEnum x; y' <- fromEnum y; z' <- fromEnum z; return $! takeEnum (enumFromThenTo x' y' z') }
+ Prelude.SafeEnum: class (UpwardEnum a, DownwardEnum a) => Enum a
- Prelude.SafeEnum: class UpwardEnum a where enumFrom x0 = build (enumFromFB x0) where {-# INLINE[0] enumFromFB #-} enumFromFB x cons nil = x `cons` case succ x of { Nothing -> nil Just y -> enumFromFB y cons nil } enumFromTo x0 z0 = build (enumFromToFB x0 z0) where {-# INLINE[0] enumFromToFB #-} enumFromToFB x z cons nil | x `succeeds` z = nil | otherwise = x `cons` case succ x of { Nothing -> nil Just y -> enumFromToFB y z cons nil }
+ Prelude.SafeEnum: class UpwardEnum a
Files
- CHANGELOG +4/−0
- README +0/−50
- README.md +51/−0
- prelude-safeenum.cabal +26/−25
- src/Data/Number/CalkinWilf.hs +4/−4
- src/Prelude/SafeEnum.hs +10/−9
CHANGELOG view
@@ -1,3 +1,7 @@+0.1.1.3 (2021-10-17):+ - Updated maintainer emails/urls+ - General metadata cleanup+ - Started using GithubActions for CI; no code changes. 0.1.1.2 (2015-05-30): - Moved VERSION to CHANGELOG 0.1.1 (2013.03.07):
− README
@@ -1,50 +0,0 @@-prelude-safeenum-================--This is a very simple package and should be easy to install. You-should be able to use any of the following standard methods to-install it.-- -- With cabal-install and without the source:- $> cabal install prelude-safeenum- - -- With cabal-install and with the source already:- $> cd prelude-safeenum- $> cabal install- - -- Without cabal-install, but with the source already:- $> cd prelude-safeenum- $> runhaskell Setup.hs configure --user- $> runhaskell Setup.hs build- $> runhaskell Setup.hs test- $> runhaskell Setup.hs haddock --hyperlink-source- $> runhaskell Setup.hs copy- $> runhaskell Setup.hs register--The test step is optional and currently does nothing. The Haddock-step is also optional.---Portability-===========--An attempt has been made to keep this library portable; however,-it does rely on a few language extensions. All the required language-extensions are:-- CPP- GeneralizedNewtypeDeriving- MagicHash -- only for GHC- Trustworthy -- only for GHC >= 7.1--The GeneralizedNewtypeDeriving extension is used for brevity in-Data.Number.CalkinWilf. If you'd like to use this package with a-compiler that does not support that extension, contact the maintainer-and it can be removed.--This package is only "Trustworthy" rather than "Safe" for two-reasons: (1) Data.Number.CalkinWilf uses GeneralizedNewtypeDeriving,-and (2) Prelude.SafeEnum imports GHC.Exts for build/foldr fusion-and for the Char instances.------------------------------------------------------------- fin.
+ README.md view
@@ -0,0 +1,51 @@+prelude-safeenum+================+[](https://hackage.haskell.org/package/prelude-safeenum)+[](https://github.com/wrengr/prelude-safeenum/actions?query=workflow%3Aci)+[](http://packdeps.haskellers.com/specific?package=prelude-safeenum)++A redefinition of the Prelude's `Enum` class in order to render it+safe. That is, the Haskell Language Report defines `pred`, `succ`,+`fromEnum`, and `toEnum` to be partial functions when the type is+`Bounded`. This is unacceptable. We define a new type-class hierarchy+for enumeration which is safe and also generalizes to cover types+which can only be enumerated in one direction.+++## Install++This is a very simple package and should be easy to install. You+should be able to use the standard:++ $> cabal install prelude-safeenum+++## Portability++An attempt has been made to keep this library portable; however,+it does rely on a few language extensions. All the required language+extensions are:++* CPP+* GeneralizedNewtypeDeriving+* MagicHash - only for GHC+* Trustworthy - only for GHC >= 7.1++The GeneralizedNewtypeDeriving extension is used for brevity in+Data.Number.CalkinWilf. If you'd like to use this package with a+compiler that does not support that extension, contact the maintainer+and it can be removed.++This package is only "Trustworthy" rather than "Safe" for two+reasons: (1) Data.Number.CalkinWilf uses GeneralizedNewtypeDeriving,+and (2) Prelude.SafeEnum imports GHC.Exts for build/foldr fusion+and for the Char instances.+++## Links++* [Website](http://wrengr.org)+* [Blog](http://winterkoninkje.dreamwidth.org/)+* [Twitter](https://twitter.com/wrengr)+* [Hackage](http://hackage.haskell.org/package/prelude-safeenum)+* [GitHub](https://github.com/wrengr/prelude-safeenum)
prelude-safeenum.cabal view
@@ -1,19 +1,19 @@ ------------------------------------------------------------------- wren gayle romano <wren@community.haskell.org> ~ 2015.05.30+-- wren gayle romano <wren@cpan.org> ~ 2021.10.17 ---------------------------------------------------------------- --- By and large Cabal >=1.2 is fine; but >= 1.6 gives tested-with:--- and source-repository:.-Cabal-Version: >= 1.6+-- Cabal >=1.10 is required by Hackage.+Cabal-Version: >= 1.10 Build-Type: Simple Name: prelude-safeenum-Version: 0.1.1.2+Version: 0.1.1.3 Stability: provisional-Homepage: http://code.haskell.org/~wren/+Homepage: https://wrengr.org/software/hackage.html+Bug-Reports: https://github.com/wrengr/prelude-safeenum/issues Author: wren gayle romano-Maintainer: wren@community.haskell.org-Copyright: Copyright (c) 2012--2015 wren gayle romano+Maintainer: wren@cpan.org+Copyright: Copyright (c) 2012–2021 wren gayle romano License: BSD3 License-File: LICENSE @@ -29,31 +29,32 @@ generalizes to cover types which can only be enumerated in one direction. -Tested-With:- GHC ==6.12.1, GHC ==7.6.1, GHC ==7.8.0 Extra-source-files:- AUTHORS, README, CHANGELOG-Source-Repository head- Type: darcs- Location: http://community.haskell.org/~wren/prelude-safeenum+ AUTHORS, README.md, CHANGELOG +-- This should work as far back as GHC 6.12.1, but we don't verify that by CI.+-- <https://github.com/wrengr/prelude-safeenum/actions?query=workflow%3Aci>+Tested-With:+ GHC ==8.0.2,+ GHC ==8.2.2,+ GHC ==8.4.4,+ GHC ==8.6.5,+ GHC ==8.8.4,+ GHC ==8.10.3,+ GHC ==9.0.1+ -----------------------------------------------------------------Flag base4- Default: True- Description: base-4.0 emits "Prelude deprecated" messages in- order to get people to be explicit about which- version of base they use.+Source-Repository head+ Type: git+ Location: https://github.com/wrengr/prelude-safeenum.git+ ---------------------------------------------------------------- Library+ Default-Language: Haskell2010 Hs-Source-Dirs: src Exposed-Modules: Prelude.SafeEnum , Data.Number.CalkinWilf- - -- I think this is all that needs doing to get rid of the warnings?- if flag(base4)- Build-Depends: base >= 4 && < 5- else- Build-Depends: base < 4+ Build-Depends: base >= 4 && < 5 ---------------------------------------------------------------- ----------------------------------------------------------- fin.
src/Data/Number/CalkinWilf.hs view
@@ -5,12 +5,12 @@ {-# LANGUAGE Trustworthy #-} #endif ------------------------------------------------------------------- 2013.06.01+-- 2021.10.17 -- | -- Module : Data.Number.CalkinWilf--- Copyright : 2012--2015 wren gayle romano+-- Copyright : 2012--2021 wren gayle romano -- License : BSD3--- Maintainer : wren@community.haskell.org+-- Maintainer : wren@cpan.org -- Stability : provisional -- Portability : Haskell98 + CPP + GeneralizedNewtypeDeriving --@@ -102,7 +102,7 @@ igcd :: Integral a => a -> a -> (a,[Bool]) {-# SPECIALIZE igcd :: Integer -> Integer -> (Integer,[Bool]) #-} igcd 0 0 = (0,[])-igcd m n +igcd m n | m < 0 || n < 0 = error "igcd is undefined on negative arguments" | otherwise = case compare m n of
src/Prelude/SafeEnum.hs view
@@ -7,12 +7,12 @@ {-# LANGUAGE Trustworthy #-} #endif ------------------------------------------------------------------- 2014.03.07+-- 2021.10.17 -- | -- Module : Prelude.SafeEnum--- Copyright : 2012--2015 wren gayle romano+-- Copyright : 2012--2021 wren gayle romano -- License : BSD3--- Maintainer : wren@community.haskell.org+-- Maintainer : wren@cpan.org -- Stability : provisional -- Portability : Haskell98 + CPP (+ MagicHash) --@@ -35,12 +35,13 @@ -- it's advisable that they do (for your sanity). However, we also -- ensure that the notion of enumeration (in either direction) is -- well-defined, which rules out instances for 'Float' and 'Double',--- and renders instances for 'Ratio' problematic. 'Ratio' instances--- /can/ be provided so long as the base type is integral and--- enumerable; but they must be done in an obscure order[2] that--- does not coincide with 'Ord'. Since this is not what people may--- expect, we only provide an instance for the newtype 'CalkinWilf',--- not for 'Ratio' itself.+-- and renders instances for 'Data.Ratio.Ratio' problematic.+-- 'Data.Ratio.Ratio' instances /can/ be provided so long as the+-- base type is integral and enumerable; but they must be done in+-- an obscure order[2] that does not coincide with 'Ord'. Since+-- this is not what people may expect, we only provide an instance+-- for the newtype 'Data.Number.CalkinWilf.CalkinWilf', not for+-- 'Data.Ratio.Ratio' itself. -- -- The @MagicHash@ extension is only actually required if on GHC. -- This extension is used only so that the implementation of the