packages feed

unpacked-maybe-numeric 0.1.0.0 → 0.1.1.0

raw patch · 4 files changed

+143/−17 lines, 4 filesdep +wide-wordnew-uploaderPVP ok

version bump matches the API change (PVP)

Dependencies added: wide-word

API changes (from Hackage documentation)

+ Data.Maybe.Unpacked.Numeric.Word128: Maybe :: (# (# #) | (# Word#, Word# #) #) -> Maybe
+ Data.Maybe.Unpacked.Numeric.Word128: catMaybes :: [Maybe] -> [Word128]
+ Data.Maybe.Unpacked.Numeric.Word128: data Maybe
+ Data.Maybe.Unpacked.Numeric.Word128: fromBaseMaybe :: Maybe Word128 -> Maybe
+ Data.Maybe.Unpacked.Numeric.Word128: fromMaybe :: Word128 -> Maybe -> Word128
+ Data.Maybe.Unpacked.Numeric.Word128: instance GHC.Classes.Eq Data.Maybe.Unpacked.Numeric.Word128.Maybe
+ Data.Maybe.Unpacked.Numeric.Word128: instance GHC.Classes.Ord Data.Maybe.Unpacked.Numeric.Word128.Maybe
+ Data.Maybe.Unpacked.Numeric.Word128: instance GHC.Read.Read Data.Maybe.Unpacked.Numeric.Word128.Maybe
+ Data.Maybe.Unpacked.Numeric.Word128: instance GHC.Show.Show Data.Maybe.Unpacked.Numeric.Word128.Maybe
+ Data.Maybe.Unpacked.Numeric.Word128: isJust :: Maybe -> Bool
+ Data.Maybe.Unpacked.Numeric.Word128: isNothing :: Maybe -> Bool
+ Data.Maybe.Unpacked.Numeric.Word128: just :: Word128 -> Maybe
+ Data.Maybe.Unpacked.Numeric.Word128: listToMaybe :: [Word128] -> Maybe
+ Data.Maybe.Unpacked.Numeric.Word128: mapMaybe :: (a -> Maybe) -> [a] -> [Word128]
+ Data.Maybe.Unpacked.Numeric.Word128: maybe :: a -> (Word128 -> a) -> Maybe -> a
+ Data.Maybe.Unpacked.Numeric.Word128: maybeToList :: Maybe -> [Word128]
+ Data.Maybe.Unpacked.Numeric.Word128: nothing :: Maybe
+ Data.Maybe.Unpacked.Numeric.Word128: toBaseMaybe :: Maybe -> Maybe Word128

Files

src/Data/Maybe/Unpacked/Numeric/Int32.hs view
@@ -25,7 +25,6 @@   import Prelude hiding (Maybe,maybe) -import GHC.Base (build) import GHC.Exts  import GHC.Int (Int32(I32#)) 
src/Data/Maybe/Unpacked/Numeric/Int8.hs view
@@ -25,7 +25,6 @@  import Prelude hiding (Maybe,maybe) -import GHC.Base (build) import GHC.Exts  import GHC.Int (Int8(I8#)) 
+ src/Data/Maybe/Unpacked/Numeric/Word128.hs view
@@ -0,0 +1,122 @@+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE MagicHash #-}+{-# LANGUAGE UnboxedSums #-}+{-# LANGUAGE UnboxedTuples #-}++module Data.Maybe.Unpacked.Numeric.Word128+  ( Maybe(..)+  , just+  , nothing++  , maybe++  , isJust+  , isNothing+  , fromMaybe+  , listToMaybe+  , maybeToList+  , catMaybes+  , mapMaybe++  , toBaseMaybe+  , fromBaseMaybe+  ) where   ++import Prelude hiding (Maybe,maybe)++import Data.WideWord (Word128(..))+import GHC.Base (build)+import GHC.Exts (Word#)+import GHC.Word (Word64(W64#))++import GHC.Read (Read(readPrec))+import Text.Read (parens, Lexeme(Ident), lexP, (+++))+import Text.ParserCombinators.ReadPrec (prec, step)++import qualified Prelude as P++data Maybe = Maybe (# (# #) | (# Word#, Word# #) #)++instance Eq Maybe where+  ma == mb =+    maybe (isNothing mb)+          (\a -> maybe False (\b -> a == b) mb) ma+    +instance Ord Maybe where+  compare ma mb = maybe LT (\a -> maybe GT (compare a) mb) ma  ++instance Show Maybe where+  showsPrec p (Maybe m) = case m of+    (# (# #) | #) -> showString "nothing"+    (# | (# wa, wb #) #) -> showParen (p > 10)+      $ showString "just "+      . showsPrec 11 (Word128 (W64# wa) (W64# wb))++instance Read Maybe where+  readPrec = parens $ nothingP +++ justP+    where+      nothingP = prec 10 $ do+        Ident "nothing" <- lexP+        return nothing+      justP = prec 10 $ do+        Ident "just" <- lexP+        a <- step readPrec+        return (just a)++listToMaybe :: [Word128] -> Maybe+listToMaybe [] = nothing+listToMaybe (x:_) = just x++maybeToList :: Maybe -> [Word128]+maybeToList = maybe [] (: [])++catMaybes :: [Maybe] -> [Word128]+catMaybes = mapMaybe id++mapMaybe :: (a -> Maybe) -> [a] -> [Word128]+mapMaybe _ [] = []+mapMaybe f (a : as) =+  let ws = mapMaybe f as+  in maybe ws (: ws) (f a)+{-# NOINLINE [1] mapMaybe #-}++{-# RULES+"mapMaybe"     [~1] forall f xs. mapMaybe f xs+                    = build (\c n -> foldr (mapMaybeFB c f) n xs)+"mapMaybeList" [1]  forall f. foldr (mapMaybeFB (:) f) [] = mapMaybe f+  #-}++{-# NOINLINE [0] mapMaybeFB #-}+mapMaybeFB :: (Word128 -> r -> r) -> (a -> Maybe) -> a -> r -> r+mapMaybeFB cons f x next = maybe next (flip cons next) (f x)++isNothing :: Maybe -> Bool+isNothing = maybe True (const False)++isJust :: Maybe -> Bool+isJust = maybe False (const True)++nothing :: Maybe+nothing = Maybe (# (# #) | #)++just :: Word128 -> Maybe+just (Word128 (W64# wa) (W64# wb)) = Maybe (# | (# wa, wb #) #)++fromMaybe :: Word128 -> Maybe -> Word128+fromMaybe a (Maybe m) = case m of+  (# (# #) | #) -> a+  (# | (# wa, wb #) #) -> Word128 (W64# wa) (W64# wb)++maybe :: a -> (Word128 -> a) -> Maybe -> a+maybe a f (Maybe m) = case m of+  (# (# #) | #) -> a+  (# | (# wa, wb #) #) -> f (Word128 (W64# wa) (W64# wb))++toBaseMaybe :: Maybe -> P.Maybe Word128+toBaseMaybe = maybe P.Nothing P.Just++fromBaseMaybe :: P.Maybe Word128 -> Maybe+fromBaseMaybe = P.maybe nothing just++
unpacked-maybe-numeric.cabal view
@@ -1,24 +1,25 @@+cabal-version: 2.2 name: unpacked-maybe-numeric-version: 0.1.0.0+version: 0.1.1.0 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}-             .-             All of the numeric types inside the `Maybe` are unboxed, while the `Maybe` value-             itself is represented as an Unboxed Sum (though for sub-machine-size Int/Word values,-             the `Maybe` is just a wrapper around the underlying type, with out-of-bounds corresponding-             to the 'Nothing' value. Thus, the usage of these constructors is unsafe, as this is only-             checked internally).+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}+  .+  All of the numeric types inside the `Maybe` are unboxed, while the `Maybe` value+  itself is represented as an Unboxed Sum. However, for sub-machine-size Int/Word values,+  the `Maybe` is just a wrapper around the underlying type, with out-of-bounds corresponding+  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: BSD3+license: BSD-3-Clause license-file: LICENSE build-type: Simple-cabal-version: >= 1.10 extra-source-files: README.md  source-repository head@@ -41,11 +42,12 @@     Data.Maybe.Unpacked.Numeric.Word16     Data.Maybe.Unpacked.Numeric.Word32     Data.Maybe.Unpacked.Numeric.Word64-  hs-source-dirs:-      src+    Data.Maybe.Unpacked.Numeric.Word128+  hs-source-dirs: src   build-depends:-      base >=4.10.1.0 && <5+    , base >=4.10.1.0 && <5     , primitive >= 0.6.4+    , wide-word >= 0.1.0.8 && < 0.2   ghc-options: -Wall -O2   default-language: Haskell2010 @@ -55,4 +57,8 @@   type: exitcode-stdio-1.0   main-is: laws.hs   hs-source-dirs: test-  build-depends: base, quickcheck-classes, unpacked-maybe-numeric, QuickCheck+  build-depends:+    , QuickCheck+    , base+    , quickcheck-classes+    , unpacked-maybe-numeric