Skip to content

Instantly share code, notes, and snippets.

@wklm
Last active November 5, 2017 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wklm/65da8a717ef4b6d94ea063782b1a6ab1 to your computer and use it in GitHub Desktop.
Save wklm/65da8a717ef4b6d94ea063782b1a6ab1 to your computer and use it in GitHub Desktop.
F# Checked arithmetic operator overloading example
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