{-# LANGUAGE ImplicitParams #-}
{-# OPTIONS_GHC -Wall -Werror #-}
module Documentation.SBV.Examples.Misc.NoDiv0 where
import Data.SBV
import GHC.Stack
checkedDiv :: (?loc :: CallStack) => SInt32 -> SInt32 -> SInt32
checkedDiv :: (?loc::CallStack) => SInt32 -> SInt32 -> SInt32
checkedDiv SInt32
x SInt32
y = forall a.
HasKind a =>
Maybe CallStack -> String -> SBool -> SBV a -> SBV a
sAssert (forall a. a -> Maybe a
Just ?loc::CallStack
?loc)
String
"Divisor should not be 0"
(SInt32
y forall a. EqSymbolic a => a -> a -> SBool
./= SInt32
0)
(SInt32
x forall a. SDivisible a => a -> a -> a
`sDiv` SInt32
y)
test1 :: IO [SafeResult]
test1 :: IO [SafeResult]
test1 = forall a. SExecutable IO a => a -> IO [SafeResult]
safe (?loc::CallStack) => SInt32 -> SInt32 -> SInt32
checkedDiv
test2 :: IO [SafeResult]
test2 :: IO [SafeResult]
test2 = forall a. SExecutable IO a => a -> IO [SafeResult]
safe forall a b. (a -> b) -> a -> b
$ \SInt32
x SInt32
y -> forall a. Mergeable a => SBool -> a -> a -> a
ite (SInt32
y forall a. EqSymbolic a => a -> a -> SBool
.== SInt32
0) SInt32
3 ((?loc::CallStack) => SInt32 -> SInt32 -> SInt32
checkedDiv SInt32
x SInt32
y)