You use a function exactly as it is defined:
len Nil = 0
len (Cons _x xs) = 1 + len xs
then,
list1 = Nil -- matches the first pattern
list2 = Cons 2 list1 -- matches the second pattern
list3 = Cons 3 list2 -- matches the second pattern
list4 = Cons 4 list3 -- matches the second pattern
and so on and so forth.
Writing out such example data by hand we need to use parentheses to correctly group the sub-terms to recreate the valid term, as e.g.
list5 = Cons 5 list4
= Cons 5 (Cons 4 list3)
= Cons 5 (Cons 4 (Cons 3 list2))
= ...
= Cons 5 (Cons 4 (Cons 3 (Cons 2 Nil)))
All this without even having looked at the data type definition.
Of course anything can be used in place of 1, 2, etc., as long as they are all of the same type, e.g. the following is also a valid term:
list54 = Cons list5 (Cons list4 Nil)
Why? Because of the data type definition,
data List a = Nil -- `Nil` constructs (is) a valid `List a` type term,
| -- OR,
Cons -- `Cons x xs` constructs (is) a valid `List a` type term, IF
a -- `x` is a valid term of type `a` , AND
(List a) -- `xs` is a valid term of type `List a`
Nil constructs (is) a valid List a type term, while Cons x xs constructs (is) a valid List a type term, if x is a valid term of type a and xs is a valid term of type List a, where a is one and the same.
So e.g. Cons 1 (Cons list2 Nil) is not a valid term according to the List a data type definition, even though the function len could seemingly handle it as well.