1

I got trouble to understand this line:

combs val = [] : concatMap (\w -> map (:w) val) (combs val)

The purpose is to create all combinations possible. It is an infinite list. (combs :: [a] -> [[a]])

I don't understand the anonymous function: \w -> map (:w) val

What does (:w) mean? What kind of mapping function is that? In my perception \w must be a list? Is it a concatination? I am confused.

1 Answer 1

3

(:w) is a section. It is equivalent to

\x -> x:w

This holds for every infix operator. We have

(+ w) = (\x -> x+w)
(* w) = (\x -> x*w)
(/ w) = (\x -> x/w)

and so on. (Only exception: (-x) is unary minus, so it is a number and not a function)

This also applies to sections where the infix operator is on the other side:

(w/) = (\x -> w/x)

In your specific case, map (:w) prepends each element of the input list to the list w, e.g.

map (:w) [a,b,c] = [a:w, b:w, c:w]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.