Last active
December 26, 2015 00:49
-
-
Save takscape/7067373 to your computer and use it in GitHub Desktop.
Stream.fromを無理やり使ったフィボナッチ数列
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
| open Core.Std | |
| let rec fib () = | |
| let tmp = ref (0, 1) in | |
| let fib_next n = | |
| match !tmp with | |
| | (cur, next) -> begin | |
| tmp := (next, cur+next); | |
| Some cur | |
| end | |
| in | |
| Stream.from fib_next | |
| let main () = | |
| let f = fib () in | |
| printf "%d\n" (Stream.next f); | |
| printf "%d\n" (Stream.next f); | |
| printf "%d\n" (Stream.next f); | |
| printf "%d\n" (Stream.next f); | |
| printf "%d\n" (Stream.next f); | |
| printf "%d\n" (Stream.next f) | |
| let () = main () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment