module Incipit.Integral where
import Data.Eq (Eq)
import Data.Maybe (Maybe (Just, Nothing))
import GHC.Num (Num)
import qualified GHC.Real as Real
import GHC.Real (Integral)
safeOp ::
Eq a =>
Num a =>
(a -> a -> b) ->
a ->
a ->
Maybe b
safeOp :: forall a b. (Eq a, Num a) => (a -> a -> b) -> a -> a -> Maybe b
safeOp a -> a -> b
op a
n = \case
a
0 ->
Maybe b
forall a. Maybe a
Nothing
a
d ->
b -> Maybe b
forall a. a -> Maybe a
Just (a -> a -> b
op a
n a
d)
{-# inline safeOp #-}
quot ::
Integral a =>
a ->
a ->
Maybe a
quot :: forall a. Integral a => a -> a -> Maybe a
quot =
(a -> a -> a) -> a -> a -> Maybe a
forall a b. (Eq a, Num a) => (a -> a -> b) -> a -> a -> Maybe b
safeOp a -> a -> a
forall a. Integral a => a -> a -> a
Real.quot
{-# inline quot #-}
rem ::
Integral a =>
a ->
a ->
Maybe a
rem :: forall a. Integral a => a -> a -> Maybe a
rem =
(a -> a -> a) -> a -> a -> Maybe a
forall a b. (Eq a, Num a) => (a -> a -> b) -> a -> a -> Maybe b
safeOp a -> a -> a
forall a. Integral a => a -> a -> a
Real.rem
{-# inline rem #-}
div ::
Integral a =>
a ->
a ->
Maybe a
div :: forall a. Integral a => a -> a -> Maybe a
div =
(a -> a -> a) -> a -> a -> Maybe a
forall a b. (Eq a, Num a) => (a -> a -> b) -> a -> a -> Maybe b
safeOp a -> a -> a
forall a. Integral a => a -> a -> a
Real.div
{-# inline div #-}
mod ::
Integral a =>
a ->
a ->
Maybe a
mod :: forall a. Integral a => a -> a -> Maybe a
mod =
(a -> a -> a) -> a -> a -> Maybe a
forall a b. (Eq a, Num a) => (a -> a -> b) -> a -> a -> Maybe b
safeOp a -> a -> a
forall a. Integral a => a -> a -> a
Real.mod
{-# inline mod #-}
quotRem ::
Integral a =>
a ->
a ->
Maybe (a, a)
quotRem :: forall a. Integral a => a -> a -> Maybe (a, a)
quotRem =
(a -> a -> (a, a)) -> a -> a -> Maybe (a, a)
forall a b. (Eq a, Num a) => (a -> a -> b) -> a -> a -> Maybe b
safeOp a -> a -> (a, a)
forall a. Integral a => a -> a -> (a, a)
Real.quotRem
{-# inline quotRem #-}
divMod ::
Integral a =>
a ->
a ->
Maybe (a, a)
divMod :: forall a. Integral a => a -> a -> Maybe (a, a)
divMod =
(a -> a -> (a, a)) -> a -> a -> Maybe (a, a)
forall a b. (Eq a, Num a) => (a -> a -> b) -> a -> a -> Maybe b
safeOp a -> a -> (a, a)
forall a. Integral a => a -> a -> (a, a)
Real.divMod
{-# inline divMod #-}