I've been trying to compare two lists in Haskell and found an answer here.
I wonder how all (flip elem listx) input works, especially for the role flip plays here.
When I take out flip it won't work anymore.
I've been trying to compare two lists in Haskell and found an answer here.
I wonder how all (flip elem listx) input works, especially for the role flip plays here.
When I take out flip it won't work anymore.
flip elem listx is equivalent to (flip elem) listx. (flip elem) is the same as elem, but with the arguments in opposite order. This is what flip does.elem is a function that takes an element and a list, and checks whether the element belongs to the list.flip elem is a function that that takes a list and an element, and checks whether the element belongs to the list.flip elem listx is a function that that takes an element, and checks whether the element belongs to listx.all takes a predicate and a list, and checks whether all elements of the list satisfy the predicate.all (flip elem listx) take a list, and checks whether all elements of the list satisfy flip elem listx. That is, whether they all belong to listx.all (flip elem listx) input checks whether all elements of input belong to listx.
all (`elem` listx) input. If you know about backticks and operator sections this should make sense.e ´elem´ listjust reads better thanelem e listmany prefer it this way.inputisn't an argument toelem, quite. Read left to right.alltakes two arguments, a function and a list, and returns true if the function is true for everything in the list. The arguments to elem are listx and one element at a time from input.