0

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?

1
  • 2:xs is a list of length at least 1, not of length 2. Commented Aug 19, 2017 at 1:36

2 Answers 2

7

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 
Sign up to request clarification or add additional context in comments.

Comments

6

End the list pattern with empty brackets:

func (2:x:[]) = expression 

This will ensure x is a single element from the list.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.