0

Whats the difference between:

(v@(x:xs)) and (v:(x:xs) 

Example function:

list [] = []
list (v@(x:xs)) = v : list xs

If i replace the (v@(x:xs)) with (v:(x:xs)) the function doesnt work.

1 Answers1

2

v@(x:xs) matches a list with one or more, with x bound to the head, xs to the tail, and v to the entire list.

v:(x:xs) matches a list with two or more elements, with v bound to the first, x to the second, and xs to the rest.

chepner
  • 497,756
  • 71
  • 530
  • 681