Skip to content

Instantly share code, notes, and snippets.

@cyberglot
Created January 1, 2015 18:26
Show Gist options
  • Select an option

  • Save cyberglot/951adecf6f988ffef272 to your computer and use it in GitHub Desktop.

Select an option

Save cyberglot/951adecf6f988ffef272 to your computer and use it in GitHub Desktop.
FP in Haskell - Readability II
plus1 :: [Int] -> [Int]
plus1 [] = []
plus1 (x:xs) = x + 1 : plus1 xs
-- plus1 [0,1,2,3]
-- > [1,2,3,4]
@Zylviij
Copy link
Copy Markdown

Zylviij commented Aug 25, 2016

Just to show off how succinct functional programming can be...
You could even show off how cool the type system can be!

-- plus1 :: Enum a => [a] -> [a]
plus1 :: [Int] -> [Int]
plus1 = map succ

-- plus1 [0, 1, 2, 3]
-- > [1, 2, 3, 4]

But I'm sure that you made the right choice in choosing a clear and straightforward example for the article.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment