Last active
November 5, 2017 17:50
-
-
Save wklm/65da8a717ef4b6d94ea063782b1a6ab1 to your computer and use it in GitHub Desktop.
F# Checked arithmetic operator overloading example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
let (+) x y = Checked.(+) x y | |
let number = Random().Next() | |
let rec guess (lower, upper) = | |
let x = (lower + upper) / 2 | |
if number > x then | |
guess (x, upper) | |
elif number < x then | |
guess (lower, x) | |
else x | |
let x = guess(Int32.MinValue, Int32.MaxValue) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment