Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
How can I make sure the pattern
func (2:xs) = expression
where 2:xs is a length 2 list doesn't match with the pattern
func (2:x:xs) = expression2
where 2:x:xs is a length 3 list?
2:xs
Adapt this as needed:
func [] = ... -- empty case func [x] = ... -- length=1 case func [x,y] = ... -- length=2 case func (x:y:z:zs) = ... -- length>=3 case
Add a comment
End the list pattern with empty brackets:
func (2:x:[]) = expression
This will ensure x is a single element from the list.
x
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
2:xsis a list of length at least 1, not of length 2.