| 0 -> None
| _ -> Some (x / y);;
-(*
+(* an Ocaml session could continue with OCaml's response:
val safe_div : int -> int -> int option = fun
# safe_div 12 2;;
- : int option = Some 6
| Some 0 -> None
| Some y -> Some (x / y));;
-(*
+(* an Ocaml session could continue with OCaml's response:
val safe_div2 : int option -> int option -> int option = <fun>
# safe_div2 (Some 12) (Some 2);;
- : int option = Some 6
| (_, None) -> None
| (Some x, Some y) -> Some (x + y);;
-(*
+(* an Ocaml session could continue with OCaml's response:
val safe_add : int option -> int option -> int option = <fun>
# safe_add (Some 12) (Some 4);;
- : int option = Some 16
Let's see our new functions in action:
<pre>
-(*
+(* an Ocaml session could continue with OCaml's response:
# safe_div3 (safe_div3 (Some 12) (Some 2)) (Some 3);;
- : int option = Some 2
# safe_div3 (safe_div3 (Some 12) (Some 0)) (Some 3);;