2:xs is a list of length at least 1, not of length 2.
- Alexey Romanov
2 Answers
7
votes
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
6
votes
End the list pattern with empty brackets:
func (2:x:[]) = expression
This will ensure x is a single element from the list.
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkRead more
2:xsis a list of length at least 1, not of length 2. - Alexey Romanov