Type signature for
const :: ∀ a b. a -> b -> a
The type signature tells us that
const is a function that takes two fully polymorphic type parameters and always returns the first parameter, untouched.
const :: ∀ a b. a -> b -> a const x _ = x
const :: ∀ a b. a -> b -> a const = \x _ -> x
f3 :: ∀ a b. a -> (b -> a) f3 x = \_ -> x
r2 = filter (const true) [1, 2, 3, 4]
const true 1, then
const true 2, etc. for each element of the array.
const will always ignore the element, and only consider
true (the first argument, since
const always ignores the its second argument).
Observe that we partially apply
true, so, each element of the list is in turn, passed as the remaining, “missing” (second) argument to
const, which is promptly always ignored. The result is that the predicate is always satisfied and all elements are kept in the resulting array.