From 12d4cc83abdb9a5d54b57ffa07d12d75d1a64064 Mon Sep 17 00:00:00 2001 From: dmitreeeee <15309757+dmitreeeee@users.noreply.github.com> Date: Thu, 4 Jul 2019 19:11:45 +0100 Subject: [PATCH] Added a page for list comprehensions in haskell (#30741) --- .../haskell/list-comprehension/index.md | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 guide/english/haskell/list-comprehension/index.md diff --git a/guide/english/haskell/list-comprehension/index.md b/guide/english/haskell/list-comprehension/index.md new file mode 100644 index 0000000000..c9484dbbca --- /dev/null +++ b/guide/english/haskell/list-comprehension/index.md @@ -0,0 +1,21 @@ +--- +title: List Comprehensions +--- + +## List Comprehensions + +List comprehensions are a powerful tool in haskell for working with sets. + +```haskell +someNumbers :: [Int] # a list of integers containing, 1, 2 and 3 +someNumbers = [1,2,3] + +allLower :: [Char] +allLower = [toLower c | c <- "Hello, World!" ] + +parity :: [(Int, Boolean)] +parity = [ ( x , even x ) | x <- [1,2,3] ] +``` +Parity produces the following set: `[ (1, False), (2, True), (3, False) ]` + +The right hand side of the list comprehension is composed of two parts; a generator and guards.