Understanding the functions elem and isInfixOf

Your problem is with the (** a) syntactic sugar. The thing is that (elem b) is just the partial application of elem, that is:

(elem b) == (\xs -> elem b xs)

However when we use back ticks to make elem infix, we get a special syntax for infix operators which works like this:

(+ a) == (\ b -> b + a)
(a +) == (\ b -> a + b)

So therefore,

(`elem` xs) == (\a -> a `elem` xs) == (\ a -> elem a xs)


(elem xs) == (\a -> elem xs a)

So in the latter case your arguments are in the wrong order, and that is what is happening in your code.

Note that the (** a) syntactic sugar works for all infix operators except - since it is also a prefix operator. This exception from the rule is discussed here and here.

Leave a Comment