You need to understand the syntax better.
Basically, there are 2 sub-syntaxes:
- syntax for types
- syntax for expressions and patterns
In the type syntax, [a]
means list of elements of type a
In the expression/pattern syntax, [a]
means the singleton list, that contains the value a
. This is equivalent to (a:[])
(a prepended to the empty list).
Hence your first function, for example, checks if it gets a singleton list. Then it takes the head of the tail of the tail of a singleton list, which will fail.
The message you're getting is because there are shapes of lists you didn't cover: namely, the empty list and lists with more than 1 element.
And, of course, you should be getting a warning for third2
, is it only covers lists with 3 or more elements. I am sure you're overlooking something.