Reputation: 43
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?
Upvotes: 0
Views: 991
Reputation: 116139
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
Upvotes: 7
Reputation: 36375
End the list pattern with empty brackets:
func (2:x:[]) = expression
This will ensure x
is a single element from the list.
Upvotes: 6