Skip to content

Instantly share code, notes, and snippets.

@henrik-ch
Created April 20, 2012 14:40
Show Gist options
  • Save henrik-ch/2429157 to your computer and use it in GitHub Desktop.
Save henrik-ch/2429157 to your computer and use it in GitHub Desktop.
Haskell list comprehensions
-- [output function | generators/predicates]
-- like this
[ x * 2| x <- [1..4]]
-- can be read as take x and multiply it with two, and get x from the list consisting of 1 to 4.
-- [2,4,6,8]
-- or like this
[ (x * 2, y - 3)| x <- [1..3], y <- [2..4]]
--[(2,-1),(2,0),(2,1),(4,-1),(4,0),(4,1),(6,-1),(6,0),(6,1)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment