Created
July 17, 2011 20:15
-
-
Save palladin/1088013 to your computer and use it in GitHub Desktop.
A beautiful fixed-point finding function
This file contains hidden or 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
| let rec iterate f value = | |
| seq { yield value; | |
| yield! iterate f (f value) } | |
| let fixedPoint f initial = | |
| iterate f initial | |
| |> Seq.pairwise | |
| |> Seq.pick (fun (first, second) -> | |
| if first = second then Some first else None) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment