Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does this symbol | mean in Haskelll

Someone can explain this coding to me.

[ x*y | x <- [2,5,10], y <- [8,10,11], x*y > 50]

I don't understand the meaning of this | symbol in haskell

like image 744
user3222659 Avatar asked Jan 22 '14 09:01

user3222659


People also ask

What does AT symbol mean in Haskell?

The @ Symbol is used to both give a name to a parameter and match that parameter against a pattern that follows the @ . It's not specific to lists and can also be used with other data structures.

What does == mean in Haskell?

The == is an operator for comparing if two things are equal. It is quite normal haskell function with type "Eq a => a -> a -> Bool". The type tells that it works on every type of a value that implements Eq typeclass, so it is kind of overloaded.

What is Backticks in Haskell?

Backticks make a function an infix operator. This is sometimes a more natural way to write expressions. Parentheses around a binary operator turns it into a two-argument function. This is most useful when you want to pass it as an argument (later).

What does ++ do Haskell?

The ++ operator is the list concatenation operator which takes two lists as operands and "combines" them into a single list.


1 Answers

You should read it as "where" or "such that" -

-- x * y where x is from [2,5,10] and y is from [8,10,11] and x * y > 50
[  x * y   |   x    <-   [2,5,10],    y    <-   [8,10,11],    x * y > 50]

or, alternatively, if you're familiar with Python and its list comprehensions, you might read it as "for"

-- [x * y for x in [2,5,10] for y in [8,10,11] if x * y > 50]
   [x * y  |  x <- [2,5,10],    y <- [8,10,11],   x * y > 50]
like image 82
Chris Taylor Avatar answered Sep 24 '22 16:09

Chris Taylor