mirror of
https://github.com/github/semantic.git
synced 2024-12-26 00:12:29 +03:00
Ditto, but for bitwise functions.
This commit is contained in:
parent
0329984dfa
commit
d01ad24d83
@ -51,6 +51,8 @@ module Control.Abstract.Value
|
|||||||
, runNumericFunction
|
, runNumericFunction
|
||||||
, runNumeric2Function
|
, runNumeric2Function
|
||||||
, castToInteger
|
, castToInteger
|
||||||
|
, runBitwiseFunction
|
||||||
|
, runBitwise2Function
|
||||||
, liftBitwise
|
, liftBitwise
|
||||||
, liftBitwise2
|
, liftBitwise2
|
||||||
, unsignedRShift
|
, unsignedRShift
|
||||||
@ -346,8 +348,15 @@ unsignedRShift :: (Member (Bitwise value) sig, Carrier sig m)
|
|||||||
unsignedRShift v1 v2 = send (UnsignedRShift v1 v2 pure)
|
unsignedRShift v1 v2 = send (UnsignedRShift v1 v2 pure)
|
||||||
|
|
||||||
data BitwiseFunction = BitwiseFunction (forall a . Bits a => a -> a)
|
data BitwiseFunction = BitwiseFunction (forall a . Bits a => a -> a)
|
||||||
|
|
||||||
|
runBitwiseFunction :: Bits a => BitwiseFunction -> a -> a
|
||||||
|
runBitwiseFunction (BitwiseFunction f) a = f a
|
||||||
|
|
||||||
data Bitwise2Function = Bitwise2Function (forall a . (Integral a, Bits a) => a -> a -> a)
|
data Bitwise2Function = Bitwise2Function (forall a . (Integral a, Bits a) => a -> a -> a)
|
||||||
|
|
||||||
|
runBitwise2Function :: (Integral a, Bits a) => Bitwise2Function -> a -> a -> a
|
||||||
|
runBitwise2Function (Bitwise2Function f) a b = f a b
|
||||||
|
|
||||||
data Bitwise value (m :: * -> *) k
|
data Bitwise value (m :: * -> *) k
|
||||||
= CastToInteger value (value -> m k)
|
= CastToInteger value (value -> m k)
|
||||||
| LiftBitwise BitwiseFunction value (value -> m k)
|
| LiftBitwise BitwiseFunction value (value -> m k)
|
||||||
|
@ -36,10 +36,11 @@ interpose m f = send (Interpose m f pure)
|
|||||||
runInterpose :: InterposeC eff m a -> m a
|
runInterpose :: InterposeC eff m a -> m a
|
||||||
runInterpose = runReader Nothing . runInterposeC
|
runInterpose = runReader Nothing . runInterposeC
|
||||||
|
|
||||||
newtype InterposeC eff m a = InterposeC { runInterposeC :: ReaderC (Maybe (Listener eff (InterposeC eff m))) m a }
|
newtype InterposeC (eff :: (* -> *) -> * -> *) m a = InterposeC
|
||||||
deriving (Alternative, Applicative, Functor, Monad)
|
{ runInterposeC :: ReaderC (Maybe (Listener eff (InterposeC eff m))) m a
|
||||||
|
} deriving (Alternative, Applicative, Functor, Monad)
|
||||||
|
|
||||||
newtype Listener eff m = Listener (forall n x . eff n x -> m x)
|
newtype Listener (eff :: (* -> *) -> * -> *) m = Listener (forall n x . eff n x -> m x)
|
||||||
|
|
||||||
-- -- TODO: Document the implementation of this, as it is extremely subtle.
|
-- -- TODO: Document the implementation of this, as it is extremely subtle.
|
||||||
|
|
||||||
|
@ -226,9 +226,9 @@ instance ( Member (Reader ModuleInfo) sig
|
|||||||
Abstract.Float t k -> k (Float (Number.Decimal t))
|
Abstract.Float t k -> k (Float (Number.Decimal t))
|
||||||
Abstract.Rational t k -> k (Rational (Number.Ratio t))
|
Abstract.Rational t k -> k (Rational (Number.Ratio t))
|
||||||
Abstract.LiftNumeric f arg k -> k =<< case arg of
|
Abstract.LiftNumeric f arg k -> k =<< case arg of
|
||||||
Integer (Number.Integer i) -> pure $ Integer (Number.Integer (f i))
|
Integer (Number.Integer i) -> pure $ Integer (Number.Integer (runNumericFunction f i))
|
||||||
Float (Number.Decimal d) -> pure $ Float (Number.Decimal (f d))
|
Float (Number.Decimal d) -> pure $ Float (Number.Decimal (runNumericFunction f d))
|
||||||
Rational (Number.Ratio r) -> pure $ Rational (Number.Ratio (f r))
|
Rational (Number.Ratio r) -> pure $ Rational (Number.Ratio (runNumericFunction f r))
|
||||||
other -> throwBaseError (NumericError other)
|
other -> throwBaseError (NumericError other)
|
||||||
Abstract.LiftNumeric2 f left right k -> k =<< case (left, right) of
|
Abstract.LiftNumeric2 f left right k -> k =<< case (left, right) of
|
||||||
(Integer i, Integer j) -> attemptUnsafeArithmetic (runNumeric2Function f i j) & specialize
|
(Integer i, Integer j) -> attemptUnsafeArithmetic (runNumeric2Function f i j) & specialize
|
||||||
@ -268,7 +268,7 @@ instance ( Member (Reader ModuleInfo) sig
|
|||||||
CastToInteger (Integer (Number.Integer i)) k -> k (Integer (Number.Integer i))
|
CastToInteger (Integer (Number.Integer i)) k -> k (Integer (Number.Integer i))
|
||||||
CastToInteger (Float (Number.Decimal i)) k -> k (Integer (Number.Integer (coefficient (normalize i))))
|
CastToInteger (Float (Number.Decimal i)) k -> k (Integer (Number.Integer (coefficient (normalize i))))
|
||||||
CastToInteger i k -> throwBaseError (NumericError i) >>= k
|
CastToInteger i k -> throwBaseError (NumericError i) >>= k
|
||||||
LiftBitwise operator (Integer (Number.Integer i)) k -> k . Integer . Number.Integer . operator $ i
|
LiftBitwise operator (Integer (Number.Integer i)) k -> k . Integer . Number.Integer . runNumericFunction operator $ i
|
||||||
LiftBitwise _ other k -> throwBaseError (BitwiseError other) >>= k
|
LiftBitwise _ other k -> throwBaseError (BitwiseError other) >>= k
|
||||||
LiftBitwise2 operator (Integer (Number.Integer i)) (Integer (Number.Integer j)) k -> k . Integer . Number.Integer $ operator i j
|
LiftBitwise2 operator (Integer (Number.Integer i)) (Integer (Number.Integer j)) k -> k . Integer . Number.Integer $ operator i j
|
||||||
LiftBitwise2 _ left right k -> throwBaseError (Bitwise2Error left right) >>= k
|
LiftBitwise2 _ left right k -> throwBaseError (Bitwise2Error left right) >>= k
|
||||||
|
Loading…
Reference in New Issue
Block a user