{-# 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 :: SInt32 -> SInt32 -> SInt32
checkedDiv SInt32
x SInt32
y = Maybe CallStack -> String -> SBool -> SInt32 -> SInt32
forall a.
HasKind a =>
Maybe CallStack -> String -> SBool -> SBV a -> SBV a
sAssert (CallStack -> Maybe CallStack
forall a. a -> Maybe a
Just ?loc::CallStack
CallStack
?loc)
String
"Divisor should not be 0"
(SInt32
y SInt32 -> SInt32 -> SBool
forall a. EqSymbolic a => a -> a -> SBool
./= SInt32
0)
(SInt32
x SInt32 -> SInt32 -> SInt32
forall a. SDivisible a => a -> a -> a
`sDiv` SInt32
y)
test1 :: IO [SafeResult]
test1 :: IO [SafeResult]
test1 = (SInt32 -> SInt32 -> SInt32) -> IO [SafeResult]
forall a. SExecutable IO a => a -> IO [SafeResult]
safe (?loc::CallStack) => SInt32 -> SInt32 -> SInt32
SInt32 -> SInt32 -> SInt32
checkedDiv
test2 :: IO [SafeResult]
test2 :: IO [SafeResult]
test2 = (SInt32 -> SInt32 -> SInt32) -> IO [SafeResult]
forall a. SExecutable IO a => a -> IO [SafeResult]
safe ((SInt32 -> SInt32 -> SInt32) -> IO [SafeResult])
-> (SInt32 -> SInt32 -> SInt32) -> IO [SafeResult]
forall a b. (a -> b) -> a -> b
$ \SInt32
x SInt32
y -> SBool -> SInt32 -> SInt32 -> SInt32
forall a. Mergeable a => SBool -> a -> a -> a
ite (SInt32
y SInt32 -> SInt32 -> SBool
forall a. EqSymbolic a => a -> a -> SBool
.== SInt32
0) SInt32
3 ((?loc::CallStack) => SInt32 -> SInt32 -> SInt32
SInt32 -> SInt32 -> SInt32
checkedDiv SInt32
x SInt32
y)