You can always use the Maybe type as a follows:
intDiv :: Integer -> Integer -> Maybe Integer
intDiv _ 0 = Nothing
intDiv n m = Just (div n m)
This allows you to pattern match results of divisions:
example :: Integer -> Integer -> Maybe Integer
example n m =
case intDiv 4 n of
Nothing -> Nothing
Just n' ->
case intDiv 5 m of
Nothing -> Nothing
Just m' -> Just (n' + m')
Or even better using the do notation:
example2 :: Integer -> Integer -> Maybe Integer
example2 n m = do
n' <- intDiv 4 n
m' <- intDiv 5 m
return (n' + m')
Note that example and example2 both do the same thing.
I think this is cleaner solution add NaN as a value to the Integer type.
Good luck,
Daniel Díaz.