Skip to content

Instantly share code, notes, and snippets.

@quephird
Last active August 29, 2015 14:24
Show Gist options
  • Save quephird/7484aa677828653d9a9d to your computer and use it in GitHub Desktop.
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.
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