{-# LANGUAGE BangPatterns #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE MagicHash #-} {-# LANGUAGE UnboxedSums #-} {-# LANGUAGE UnboxedTuples #-} module Data.Maybe.Unpacked.Numeric.Int64 ( Maybe(..) , just , nothing , maybe , isJust , isNothing , fromMaybe , listToMaybe , maybeToList , catMaybes , mapMaybe , toBaseMaybe , fromBaseMaybe ) where import Prelude hiding (Maybe,maybe) import GHC.Base (build) import GHC.Exts (Int#) import GHC.Int (Int64(I64#)) 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 (# (# #) | Int# #) instance Eq Maybe where Maybe ma == :: Maybe -> Maybe -> Bool == Maybe mb = Bool -> (Int64 -> Bool) -> Maybe -> Bool forall a. a -> (Int64 -> a) -> Maybe -> a maybe (Maybe -> Bool isNothing Maybe mb) (\Int64 a -> Bool -> (Int64 -> Bool) -> Maybe -> Bool forall a. a -> (Int64 -> a) -> Maybe -> a maybe Bool False (\Int64 b -> Int64 a Int64 -> Int64 -> Bool forall a. Eq a => a -> a -> Bool == Int64 b) Maybe mb) Maybe ma instance Ord Maybe where compare :: Maybe -> Maybe -> Ordering compare Maybe ma Maybe mb = Ordering -> (Int64 -> Ordering) -> Maybe -> Ordering forall a. a -> (Int64 -> a) -> Maybe -> a maybe Ordering LT (\Int64 a -> Ordering -> (Int64 -> Ordering) -> Maybe -> Ordering forall a. a -> (Int64 -> a) -> Maybe -> a maybe Ordering GT (Int64 -> Int64 -> Ordering forall a. Ord a => a -> a -> Ordering compare Int64 a) Maybe mb) Maybe ma instance Show Maybe where showsPrec :: Int -> Maybe -> ShowS showsPrec Int p (Maybe (# (# #) | Int# #) m) = case (# (# #) | Int# #) m of (# (# #) | #) -> String -> ShowS showString String "nothing" (# | Int# i #) -> Bool -> ShowS -> ShowS showParen (Int p Int -> Int -> Bool forall a. Ord a => a -> a -> Bool > Int 10) (ShowS -> ShowS) -> ShowS -> ShowS forall a b. (a -> b) -> a -> b $ String -> ShowS showString String "just " ShowS -> ShowS -> ShowS forall b c a. (b -> c) -> (a -> b) -> a -> c . Int -> Int64 -> ShowS forall a. Show a => Int -> a -> ShowS showsPrec Int 11 (Int# -> Int64 I64# Int# i) instance Read Maybe where readPrec :: ReadPrec Maybe readPrec = ReadPrec Maybe -> ReadPrec Maybe forall a. ReadPrec a -> ReadPrec a parens (ReadPrec Maybe -> ReadPrec Maybe) -> ReadPrec Maybe -> ReadPrec Maybe forall a b. (a -> b) -> a -> b $ ReadPrec Maybe nothingP ReadPrec Maybe -> ReadPrec Maybe -> ReadPrec Maybe forall a. ReadPrec a -> ReadPrec a -> ReadPrec a +++ ReadPrec Maybe justP where nothingP :: ReadPrec Maybe nothingP = do Ident String "nothing" <- ReadPrec Lexeme lexP Maybe -> ReadPrec Maybe forall (m :: * -> *) a. Monad m => a -> m a return Maybe nothing justP :: ReadPrec Maybe justP = Int -> ReadPrec Maybe -> ReadPrec Maybe forall a. Int -> ReadPrec a -> ReadPrec a prec Int 10 (ReadPrec Maybe -> ReadPrec Maybe) -> ReadPrec Maybe -> ReadPrec Maybe forall a b. (a -> b) -> a -> b $ do Ident String "just" <- ReadPrec Lexeme lexP Int64 a <- ReadPrec Int64 -> ReadPrec Int64 forall a. ReadPrec a -> ReadPrec a step ReadPrec Int64 forall a. Read a => ReadPrec a readPrec Maybe -> ReadPrec Maybe forall (m :: * -> *) a. Monad m => a -> m a return (Int64 -> Maybe just Int64 a) listToMaybe :: [Int64] -> Maybe listToMaybe :: [Int64] -> Maybe listToMaybe [] = Maybe nothing listToMaybe (Int64 x:[Int64] _) = Int64 -> Maybe just Int64 x maybeToList :: Maybe -> [Int64] maybeToList :: Maybe -> [Int64] maybeToList = [Int64] -> (Int64 -> [Int64]) -> Maybe -> [Int64] forall a. a -> (Int64 -> a) -> Maybe -> a maybe [] (Int64 -> [Int64] -> [Int64] forall a. a -> [a] -> [a] : []) catMaybes :: [Maybe] -> [Int64] catMaybes :: [Maybe] -> [Int64] catMaybes = (Maybe -> Maybe) -> [Maybe] -> [Int64] forall a. (a -> Maybe) -> [a] -> [Int64] mapMaybe Maybe -> Maybe forall a. a -> a id mapMaybe :: (a -> Maybe) -> [a] -> [Int64] mapMaybe :: (a -> Maybe) -> [a] -> [Int64] mapMaybe a -> Maybe _ [] = [] mapMaybe a -> Maybe f (a a : [a] as) = let ws :: [Int64] ws = (a -> Maybe) -> [a] -> [Int64] forall a. (a -> Maybe) -> [a] -> [Int64] mapMaybe a -> Maybe f [a] as in [Int64] -> (Int64 -> [Int64]) -> Maybe -> [Int64] forall a. a -> (Int64 -> a) -> Maybe -> a maybe [Int64] ws (Int64 -> [Int64] -> [Int64] forall a. a -> [a] -> [a] : [Int64] ws) (a -> Maybe f a 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 :: (Int64 -> r -> r) -> (a -> Maybe) -> a -> r -> r mapMaybeFB :: (Int64 -> r -> r) -> (a -> Maybe) -> a -> r -> r mapMaybeFB Int64 -> r -> r cons a -> Maybe f a x r next = r -> (Int64 -> r) -> Maybe -> r forall a. a -> (Int64 -> a) -> Maybe -> a maybe r next ((Int64 -> r -> r) -> r -> Int64 -> r forall a b c. (a -> b -> c) -> b -> a -> c flip Int64 -> r -> r cons r next) (a -> Maybe f a x) isNothing :: Maybe -> Bool isNothing :: Maybe -> Bool isNothing = Bool -> (Int64 -> Bool) -> Maybe -> Bool forall a. a -> (Int64 -> a) -> Maybe -> a maybe Bool True (Bool -> Int64 -> Bool forall a b. a -> b -> a const Bool False) isJust :: Maybe -> Bool isJust :: Maybe -> Bool isJust = Bool -> (Int64 -> Bool) -> Maybe -> Bool forall a. a -> (Int64 -> a) -> Maybe -> a maybe Bool False (Bool -> Int64 -> Bool forall a b. a -> b -> a const Bool True) nothing :: Maybe nothing :: Maybe nothing = (# (# #) | Int# #) -> Maybe Maybe (# (# #) | #) just :: Int64 -> Maybe just :: Int64 -> Maybe just (I64# Int# i) = (# (# #) | Int# #) -> Maybe Maybe (# | Int# i #) fromMaybe :: Int64 -> Maybe -> Int64 fromMaybe :: Int64 -> Maybe -> Int64 fromMaybe Int64 a (Maybe (# (# #) | Int# #) m) = case (# (# #) | Int# #) m of (# (# #) | #) -> Int64 a (# | Int# i #) -> Int# -> Int64 I64# Int# i maybe :: a -> (Int64 -> a) -> Maybe -> a maybe :: a -> (Int64 -> a) -> Maybe -> a maybe a a Int64 -> a f (Maybe (# (# #) | Int# #) m) = case (# (# #) | Int# #) m of (# (# #) | #) -> a a (# | Int# i #) -> Int64 -> a f (Int# -> Int64 I64# Int# i) toBaseMaybe :: Maybe -> P.Maybe Int64 toBaseMaybe :: Maybe -> Maybe Int64 toBaseMaybe = Maybe Int64 -> (Int64 -> Maybe Int64) -> Maybe -> Maybe Int64 forall a. a -> (Int64 -> a) -> Maybe -> a maybe Maybe Int64 forall a. Maybe a P.Nothing Int64 -> Maybe Int64 forall a. a -> Maybe a P.Just fromBaseMaybe :: P.Maybe Int64 -> Maybe fromBaseMaybe :: Maybe Int64 -> Maybe fromBaseMaybe = Maybe -> (Int64 -> Maybe) -> Maybe Int64 -> Maybe forall b a. b -> (a -> b) -> Maybe a -> b P.maybe Maybe nothing Int64 -> Maybe just