> import Prelude hiding (div) > import qualified Prelude ------------------------------------------------------------ Language E + div exception ------------------------------------------------------------ > add :: Int -> Int -> Int > add x y = x + y > sub :: Int -> Int -> Int > sub x y = x - y > div :: Int -> Int -> Either Int String > div x y = if y==0 then Right "Exception: Divide by zero" > else Left (x `Prelude.div` y) > mul :: Int -> Int -> Int > mul x y = x * y ------------------------------------------------------------ Examples ------------------------------------------------------------ x = Left 3 > x = add 1 2 y = Left 17 > y = add (mul 3 4) 5 z = Right "Exception: Divide by zero" > z = div 1 0 Uncommenting the following causes a type error: Couldn't match expected type `Int' against inferred type `Either String Int' In the second argument of `add', namely `(div 1 0)' w = add 1 (div 1 0)