Skip to content

Instantly share code, notes, and snippets.

@beala
Created May 9, 2016 04:08
Show Gist options
  • Save beala/2edeb4842a7f46c404a4ab00f26ff984 to your computer and use it in GitHub Desktop.
Save beala/2edeb4842a7f46c404a4ab00f26ff984 to your computer and use it in GitHub Desktop.
-- Eta expanded
slow :: Int -> Integer
slow i = (fmap fibs [0 ..] !! i)
where
fibs 0 = 0
fibs 1 = 1
fibs n = slow (n-2) + slow (n-1)
-- Eta reduced
fast :: Int -> Integer
fast = (fmap fibs [0 ..] !!)
where
fibs 0 = 0
fibs 1 = 1
fibs n = fast (n-2) + fast (n-1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment