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 ->
forall a. Maybe a
Nothing
a
d ->
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 =
forall a b. (Eq a, Num a) => (a -> a -> b) -> a -> a -> Maybe b
safeOp 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 =
forall a b. (Eq a, Num a) => (a -> a -> b) -> a -> a -> Maybe b
safeOp 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 =
forall a b. (Eq a, Num a) => (a -> a -> b) -> a -> a -> Maybe b
safeOp 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 =
forall a b. (Eq a, Num a) => (a -> a -> b) -> a -> a -> Maybe b
safeOp 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 =
forall a b. (Eq a, Num a) => (a -> a -> b) -> a -> a -> Maybe b
safeOp 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 =
forall a b. (Eq a, Num a) => (a -> a -> b) -> a -> a -> Maybe b
safeOp forall a. Integral a => a -> a -> (a, a)
Real.divMod
{-# inline divMod #-}