diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 085bbaf..e673360 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -6,7 +6,6 @@ on: jobs: call-workflow: - uses: byteverse/.github/.github/workflows/build.yaml@main - secrets: inherit + uses: byteverse/.github/.github/workflows/build-matrix.yaml@main with: - release: false + cabal-file: unpacked-maybe-numeric.cabal diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index bd0bbd5..9411962 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -6,7 +6,5 @@ on: jobs: call-workflow: - uses: byteverse/.github/.github/workflows/build.yaml@main + uses: byteverse/.github/.github/workflows/release.yaml@main secrets: inherit - with: - release: true diff --git a/CHANGELOG.md b/CHANGELOG.md index 486b993..2ac2dfe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog for unpacked-maybe-numeric +## 0.1.3.1 -- 2024-02-14 + +* Update package metadata. +* Fix failing test suite. + ## 0.1.1.0 -- 2019-09-28 * Add module for `Word128`-variant of `Maybe`. diff --git a/cabal.project b/cabal.project new file mode 100644 index 0000000..7ef286b --- /dev/null +++ b/cabal.project @@ -0,0 +1,2 @@ +packages: . +tests: True diff --git a/src/Data/Maybe/Unpacked/Numeric/Double.hs b/src/Data/Maybe/Unpacked/Numeric/Double.hs index 01fbc87..602d3ff 100644 --- a/src/Data/Maybe/Unpacked/Numeric/Double.hs +++ b/src/Data/Maybe/Unpacked/Numeric/Double.hs @@ -37,7 +37,13 @@ instance Eq Maybe where ma instance Ord Maybe where - compare ma mb = maybe LT (\a -> maybe GT (compare a) mb) ma + compare (Maybe ma) (Maybe mb) = case ma of + (# (# #) | #) -> case mb of + (# (# #) | #) -> EQ + (# | _ #) -> LT + (# | a #) -> case mb of + (# (# #) | #) -> GT + (# | b #) -> compare (D# a) (D# b) instance Show Maybe where showsPrec p (Maybe m) = case m of diff --git a/src/Data/Maybe/Unpacked/Numeric/Float.hs b/src/Data/Maybe/Unpacked/Numeric/Float.hs index f75e54c..26458b5 100644 --- a/src/Data/Maybe/Unpacked/Numeric/Float.hs +++ b/src/Data/Maybe/Unpacked/Numeric/Float.hs @@ -37,7 +37,13 @@ instance Eq Maybe where ma instance Ord Maybe where - compare ma mb = maybe LT (\a -> maybe GT (compare a) mb) ma + compare (Maybe ma) (Maybe mb) = case ma of + (# (# #) | #) -> case mb of + (# (# #) | #) -> EQ + (# | _ #) -> LT + (# | a #) -> case mb of + (# (# #) | #) -> GT + (# | b #) -> compare (F# a) (F# b) instance Show Maybe where showsPrec p (Maybe m) = case m of diff --git a/src/Data/Maybe/Unpacked/Numeric/Int.hs b/src/Data/Maybe/Unpacked/Numeric/Int.hs index c767bec..4976ebd 100644 --- a/src/Data/Maybe/Unpacked/Numeric/Int.hs +++ b/src/Data/Maybe/Unpacked/Numeric/Int.hs @@ -39,7 +39,13 @@ instance Eq Maybe where ma instance Ord Maybe where - compare ma mb = maybe LT (\a -> maybe GT (compare a) mb) ma + compare (Maybe ma) (Maybe mb) = case ma of + (# (# #) | #) -> case mb of + (# (# #) | #) -> EQ + (# | _ #) -> LT + (# | a #) -> case mb of + (# (# #) | #) -> GT + (# | b #) -> compare (I# a) (I# b) instance Show Maybe where showsPrec p (Maybe m) = case m of diff --git a/src/Data/Maybe/Unpacked/Numeric/Int16.hs b/src/Data/Maybe/Unpacked/Numeric/Int16.hs index 6d4f9b3..6513033 100644 --- a/src/Data/Maybe/Unpacked/Numeric/Int16.hs +++ b/src/Data/Maybe/Unpacked/Numeric/Int16.hs @@ -1,6 +1,8 @@ {-# LANGUAGE MagicHash #-} {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE UnboxedSums #-} +{-# LANGUAGE UnboxedTuples #-} +{-# LANGUAGE ViewPatterns #-} module Data.Maybe.Unpacked.Numeric.Int16 ( Maybe (..) @@ -16,9 +18,12 @@ module Data.Maybe.Unpacked.Numeric.Int16 , mapMaybe , toBaseMaybe , fromBaseMaybe + -- * Patterns + , pattern Nothing + , pattern Just ) where -import Prelude hiding (Maybe, maybe) +import Prelude hiding (Just, Maybe, Nothing, maybe) import GHC.Base (build) import GHC.Exts (Int#, (<#), (>#)) @@ -41,7 +46,13 @@ instance Eq Maybe where ma instance Ord Maybe where - compare ma mb = maybe LT (\a -> maybe GT (compare a) mb) ma + compare ma mb = case ma of + Just a -> case mb of + Just b -> compare a b + _ -> GT + _ -> case mb of + Just{} -> LT + _ -> EQ instance Show Maybe where showsPrec p m = @@ -129,3 +140,17 @@ toBaseMaybe m = maybe P.Nothing P.Just m fromBaseMaybe :: P.Maybe Int16 -> Maybe {-# INLINE fromBaseMaybe #-} fromBaseMaybe m = P.maybe nothing just m + +pattern Nothing :: Maybe +pattern Nothing = M 32768# + +pattern Just :: Int16 -> Maybe +pattern Just i <- (maybeInt16ToInt16 -> (# | i #)) + where + Just (I16# i) = M i + +maybeInt16ToInt16 :: Maybe -> (# (# #) | Int16 #) +{-# inline maybeInt16ToInt16 #-} +maybeInt16ToInt16 (M i) = case i of + 32768# -> (# (# #) | #) + _ -> (# | I16# i #) diff --git a/src/Data/Maybe/Unpacked/Numeric/Int32.hs b/src/Data/Maybe/Unpacked/Numeric/Int32.hs index 0afc3dc..3f19077 100644 --- a/src/Data/Maybe/Unpacked/Numeric/Int32.hs +++ b/src/Data/Maybe/Unpacked/Numeric/Int32.hs @@ -1,6 +1,8 @@ {-# LANGUAGE MagicHash #-} {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE UnboxedSums #-} +{-# LANGUAGE UnboxedTuples #-} +{-# LANGUAGE ViewPatterns #-} module Data.Maybe.Unpacked.Numeric.Int32 ( Maybe (..) @@ -16,9 +18,12 @@ module Data.Maybe.Unpacked.Numeric.Int32 , mapMaybe , toBaseMaybe , fromBaseMaybe + -- * Patterns + , pattern Nothing + , pattern Just ) where -import Prelude hiding (Maybe, maybe) +import Prelude hiding (Just, Maybe, Nothing, maybe) import GHC.Exts import GHC.Int (Int32) @@ -41,8 +46,13 @@ instance Eq Maybe where {-# INLINE (==) #-} instance Ord Maybe where - compare ma mb = maybe LT (\a -> maybe GT (compare a) mb) ma - {-# INLINE compare #-} + compare ma mb = case ma of + Just a -> case mb of + Just b -> compare a b + _ -> GT + _ -> case mb of + Just{} -> LT + _ -> EQ instance Show Maybe where showsPrec p m = @@ -130,3 +140,17 @@ toBaseMaybe m = maybe P.Nothing P.Just m fromBaseMaybe :: P.Maybe Int32 -> Maybe {-# INLINE fromBaseMaybe #-} fromBaseMaybe m = P.maybe nothing just m + +pattern Nothing :: Maybe +pattern Nothing = M 2147483648# + +pattern Just :: Int32 -> Maybe +pattern Just i <- (maybeInt32ToInt32 -> (# | i #)) + where + Just (I32# i) = M i + +maybeInt32ToInt32 :: Maybe -> (# (# #) | Int32 #) +{-# inline maybeInt32ToInt32 #-} +maybeInt32ToInt32 (M i) = case i of + 2147483648# -> (# (# #) | #) + _ -> (# | I32# i #) diff --git a/src/Data/Maybe/Unpacked/Numeric/Int64.hs b/src/Data/Maybe/Unpacked/Numeric/Int64.hs index b0da53b..446b94e 100644 --- a/src/Data/Maybe/Unpacked/Numeric/Int64.hs +++ b/src/Data/Maybe/Unpacked/Numeric/Int64.hs @@ -39,7 +39,13 @@ instance Eq Maybe where ma instance Ord Maybe where - compare ma mb = maybe LT (\a -> maybe GT (compare a) mb) ma + compare (Maybe ma) (Maybe mb) = case ma of + (# (# #) | #) -> case mb of + (# (# #) | #) -> EQ + (# | _ #) -> LT + (# | a #) -> case mb of + (# (# #) | #) -> GT + (# | b #) -> compare (I64# a) (I64# b) instance Show Maybe where showsPrec p (Maybe m) = case m of diff --git a/src/Data/Maybe/Unpacked/Numeric/Int8.hs b/src/Data/Maybe/Unpacked/Numeric/Int8.hs index 394aa1f..334f06a 100644 --- a/src/Data/Maybe/Unpacked/Numeric/Int8.hs +++ b/src/Data/Maybe/Unpacked/Numeric/Int8.hs @@ -1,6 +1,8 @@ {-# LANGUAGE MagicHash #-} {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE UnboxedSums #-} +{-# LANGUAGE UnboxedTuples #-} +{-# LANGUAGE ViewPatterns #-} module Data.Maybe.Unpacked.Numeric.Int8 ( Maybe (..) @@ -16,9 +18,12 @@ module Data.Maybe.Unpacked.Numeric.Int8 , mapMaybe , toBaseMaybe , fromBaseMaybe + -- * Patterns + , pattern Nothing + , pattern Just ) where -import Prelude hiding (Maybe, maybe) +import Prelude hiding (Just, Maybe, Nothing, maybe) import GHC.Exts import GHC.Int (Int8) @@ -40,7 +45,13 @@ instance Eq Maybe where ma instance Ord Maybe where - compare ma mb = maybe LT (\a -> maybe GT (compare a) mb) ma + compare ma mb = case ma of + Just a -> case mb of + Just b -> compare a b + _ -> GT + _ -> case mb of + Just{} -> LT + _ -> EQ instance Show Maybe where showsPrec p m = @@ -128,3 +139,17 @@ toBaseMaybe m = maybe P.Nothing P.Just m fromBaseMaybe :: P.Maybe Int8 -> Maybe {-# INLINE fromBaseMaybe #-} fromBaseMaybe m = P.maybe nothing just m + +pattern Nothing :: Maybe +pattern Nothing = M 128# + +pattern Just :: Int8 -> Maybe +pattern Just i <- (maybeInt8ToInt8 -> (# | i #)) + where + Just (I8# i) = M i + +maybeInt8ToInt8 :: Maybe -> (# (# #) | Int8 #) +{-# inline maybeInt8ToInt8 #-} +maybeInt8ToInt8 (M i) = case i of + 128# -> (# (# #) | #) + _ -> (# | I8# i #) diff --git a/src/Data/Maybe/Unpacked/Numeric/Word.hs b/src/Data/Maybe/Unpacked/Numeric/Word.hs index c88ee76..762d313 100644 --- a/src/Data/Maybe/Unpacked/Numeric/Word.hs +++ b/src/Data/Maybe/Unpacked/Numeric/Word.hs @@ -39,7 +39,13 @@ instance Eq Maybe where ma instance Ord Maybe where - compare ma mb = maybe LT (\a -> maybe GT (compare a) mb) ma + compare (Maybe ma) (Maybe mb) = case ma of + (# (# #) | #) -> case mb of + (# (# #) | #) -> EQ + (# | _ #) -> LT + (# | a #) -> case mb of + (# (# #) | #) -> GT + (# | b #) -> compare (W# a) (W# b) instance Show Maybe where showsPrec p (Maybe m) = case m of diff --git a/src/Data/Maybe/Unpacked/Numeric/Word16.hs b/src/Data/Maybe/Unpacked/Numeric/Word16.hs index 940ac1b..51d8d7b 100644 --- a/src/Data/Maybe/Unpacked/Numeric/Word16.hs +++ b/src/Data/Maybe/Unpacked/Numeric/Word16.hs @@ -1,6 +1,7 @@ {-# LANGUAGE MagicHash #-} {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE UnboxedTuples #-} +{-# LANGUAGE ViewPatterns #-} module Data.Maybe.Unpacked.Numeric.Word16 ( Maybe (..) @@ -16,9 +17,12 @@ module Data.Maybe.Unpacked.Numeric.Word16 , mapMaybe , toBaseMaybe , fromBaseMaybe + -- * Patterns + , pattern Nothing + , pattern Just ) where -import Prelude hiding (Maybe, maybe) +import Prelude hiding (Just, Maybe, Nothing, maybe) import GHC.Base (build) import GHC.Exts (Word#) @@ -41,7 +45,13 @@ instance Eq Maybe where ma instance Ord Maybe where - compare ma mb = maybe LT (\a -> maybe GT (compare a) mb) ma + compare ma mb = case ma of + Just a -> case mb of + Just b -> compare a b + _ -> GT + _ -> case mb of + Just{} -> LT + _ -> EQ instance Show Maybe where showsPrec p (Maybe m) = case m of @@ -117,3 +127,13 @@ toBaseMaybe = maybe P.Nothing P.Just fromBaseMaybe :: P.Maybe Word16 -> Maybe fromBaseMaybe = P.maybe nothing just + +pattern Nothing :: Maybe +pattern Nothing = Maybe (# (# #) | #) + +pattern Just :: Word16 -> Maybe +pattern Just i <- Maybe (# | (W16# -> i) #) + where + Just (W16# i) = Maybe (# | i #) + +{-# COMPLETE Nothing, Just #-} diff --git a/src/Data/Maybe/Unpacked/Numeric/Word32.hs b/src/Data/Maybe/Unpacked/Numeric/Word32.hs index 46e7915..786ba02 100644 --- a/src/Data/Maybe/Unpacked/Numeric/Word32.hs +++ b/src/Data/Maybe/Unpacked/Numeric/Word32.hs @@ -56,7 +56,13 @@ instance Eq Maybe where ma instance Ord Maybe where - compare ma mb = maybe LT (\a -> maybe GT (compare a) mb) ma + compare ma mb = case ma of + Just a -> case mb of + Just b -> compare a b + _ -> GT + _ -> case mb of + Just{} -> LT + _ -> EQ instance Show Maybe where showsPrec p (Maybe m) = case m of diff --git a/src/Data/Maybe/Unpacked/Numeric/Word64.hs b/src/Data/Maybe/Unpacked/Numeric/Word64.hs index ca08b45..040fb70 100644 --- a/src/Data/Maybe/Unpacked/Numeric/Word64.hs +++ b/src/Data/Maybe/Unpacked/Numeric/Word64.hs @@ -39,7 +39,13 @@ instance Eq Maybe where ma instance Ord Maybe where - compare ma mb = maybe LT (\a -> maybe GT (compare a) mb) ma + compare (Maybe ma) (Maybe mb) = case ma of + (# (# #) | #) -> case mb of + (# (# #) | #) -> EQ + (# | _ #) -> LT + (# | a #) -> case mb of + (# (# #) | #) -> GT + (# | b #) -> compare (W64# a) (W64# b) instance Show Maybe where showsPrec p (Maybe m) = case m of diff --git a/src/Data/Maybe/Unpacked/Numeric/Word8.hs b/src/Data/Maybe/Unpacked/Numeric/Word8.hs index 902ebed..168fdd3 100644 --- a/src/Data/Maybe/Unpacked/Numeric/Word8.hs +++ b/src/Data/Maybe/Unpacked/Numeric/Word8.hs @@ -1,6 +1,7 @@ {-# LANGUAGE MagicHash #-} {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE UnboxedTuples #-} +{-# LANGUAGE ViewPatterns #-} module Data.Maybe.Unpacked.Numeric.Word8 ( Maybe (..) @@ -16,9 +17,12 @@ module Data.Maybe.Unpacked.Numeric.Word8 , mapMaybe , toBaseMaybe , fromBaseMaybe + -- * Patterns + , pattern Nothing + , pattern Just ) where -import Prelude hiding (Maybe, maybe) +import Prelude hiding (Just, Maybe, Nothing, maybe) import GHC.Base (build) import GHC.Exts (Word#) @@ -41,7 +45,13 @@ instance Eq Maybe where ma instance Ord Maybe where - compare ma mb = maybe LT (\a -> maybe GT (compare a) mb) ma + compare ma mb = case ma of + Just a -> case mb of + Just b -> compare a b + _ -> GT + _ -> case mb of + Just{} -> LT + _ -> EQ instance Show Maybe where showsPrec p (Maybe m) = case m of @@ -117,3 +127,13 @@ toBaseMaybe = maybe P.Nothing P.Just fromBaseMaybe :: P.Maybe Word8 -> Maybe fromBaseMaybe = P.maybe nothing just + +pattern Nothing :: Maybe +pattern Nothing = Maybe (# (# #) | #) + +pattern Just :: Word8 -> Maybe +pattern Just i <- Maybe (# | (W8# -> i) #) + where + Just (W8# i) = Maybe (# | i #) + +{-# COMPLETE Nothing, Just #-} diff --git a/unpacked-maybe-numeric.cabal b/unpacked-maybe-numeric.cabal index d1e8806..efbda5a 100644 --- a/unpacked-maybe-numeric.cabal +++ b/unpacked-maybe-numeric.cabal @@ -1,7 +1,7 @@ -cabal-version: 2.2 -name: unpacked-maybe-numeric -version: 0.1.3.0 -synopsis: maybes of numeric values with fewer indirections +cabal-version: 3.0 +name: unpacked-maybe-numeric +version: 0.1.3.1 +synopsis: maybes of numeric values with fewer indirections description: This library provides one `Maybe` type per the usual numeric types: Float, Double, Complex {Float|Double}, Int{8|16|32|64}, and Word{8|16|32|64|128} @@ -12,18 +12,27 @@ description: to the `Nothing` value. Thus, the use of these constructors is unsafe, as this is only checked internally. -homepage: https://github.com/andrewthad/unpacked-maybe-numeric#readme -bug-reports: https://github.com/andrewthad/unpacked-maybe-numeric/issues -author: Andrew Martin, chessai -maintainer: andrew.thaddeus@gmail.com, chessai1996@gmail.com -category: Data -copyright: 2018 Andrew Martin -license: BSD-3-Clause -license-file: LICENSE -build-type: Simple -extra-source-files: README.md +homepage: https://github.com/byteverse/unpacked-maybe-numeric +bug-reports: https://github.com/byteverse/unpacked-maybe-numeric/issues +author: Andrew Martin, chessai +maintainer: amartin@layer3com.com, chessai1996@gmail.com +category: Data +copyright: 2018 Andrew Martin +license: BSD-3-Clause +license-file: LICENSE +build-type: Simple +extra-doc-files: + CHANGELOG.md + README.md + +tested-with: GHC ==9.4.8 || ==9.6.3 || ==9.8.1 + +common build-settings + default-language: Haskell2010 + ghc-options: -Wall -Wunused-packages library + import: build-settings exposed-modules: Data.Maybe.Unpacked.Numeric.Complex.Double Data.Maybe.Unpacked.Numeric.Complex.Float @@ -41,32 +50,28 @@ library Data.Maybe.Unpacked.Numeric.Word64 Data.Maybe.Unpacked.Numeric.Word8 - hs-source-dirs: src + hs-source-dirs: src build-depends: , base >=4.17.1.0 && <5 - , primitive >=0.6.4 , wide-word >=0.1.0.8 && <0.2 , word-compat >=0.0.4 && <0.1 - ghc-options: -Wall -O2 - default-language: Haskell2010 + ghc-options: -O2 test-suite spec - default-language: Haskell2010 - ghc-options: -Wall - type: exitcode-stdio-1.0 - main-is: spec.hs - hs-source-dirs: test + import: build-settings + type: exitcode-stdio-1.0 + main-is: spec.hs + hs-source-dirs: test build-depends: , base , unpacked-maybe-numeric test-suite laws - default-language: Haskell2010 - ghc-options: -Wall - type: exitcode-stdio-1.0 - main-is: laws.hs - hs-source-dirs: test + import: build-settings + type: exitcode-stdio-1.0 + main-is: laws.hs + hs-source-dirs: test build-depends: , base , QuickCheck @@ -75,4 +80,4 @@ test-suite laws source-repository head type: git - location: https://github.com/andrewthad/unpacked-maybe-numeric + location: git://github.com/byteverse/unpacked-maybe-numeric.git