Last active
August 29, 2015 14:24
-
-
Save quephird/7484aa677828653d9a9d to your computer and use it in GitHub Desktop.
This is a rewrite of the example chapter 2 of Elm by Example that is compatible with Elm 0.15 and 2.1.0 of the core libraries.
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
module Fibonacci where | |
import List exposing ((::), head, map2, reverse, tail) | |
import Maybe exposing (andThen) | |
fibonacci : Int -> List Int | |
fibonacci n = | |
let fibonacci' n acc = | |
if n <= 2 | |
then acc | |
else | |
case ((head acc), ((tail acc) `andThen` head)) of | |
(Just n', Just n'') -> fibonacci' (n-1) ((n'+n'') :: acc) | |
_ -> [] | |
in fibonacci' n [1,1] |> reverse |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment