Skip to content

Instantly share code, notes, and snippets.

@takscape
Last active December 26, 2015 00:49
Show Gist options
  • Select an option

  • Save takscape/7067373 to your computer and use it in GitHub Desktop.

Select an option

Save takscape/7067373 to your computer and use it in GitHub Desktop.
Stream.fromを無理やり使ったフィボナッチ数列
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