Reputation: 432
I am mostly unsure about what x' represents here. Any explanations would be appreciated.
count :: Char -> String -> Int
count x xs = length [x'|x'<-xs, x==x']
Upvotes: 0
Views: 121
Reputation: 476584
x'
is a variable that represents the Char
s in the String
.
You can see this list comprehension as something similar in Python:
len([y for y in xs if x == y])
It will thus enumerate over the Char
s in the string, and check if the Char
matches with the query x
, if that holds it will add that to the list.
In Python however, an identifier can not contain a quote. In haskell that is often used to mimic the prime symbol [wiki] to denote that something is similar to the item without the prime. It thus means that x'
is somehow a bit similar to x
.
Upvotes: 2