2021 | OriginalPaper | Chapter
10. Lists and Recursion
Authors : Donald Sannella, Michael Fourman, Haoran Peng, Philip Wadler
Published in: Introduction to Computation
Publisher: Springer International Publishing
Activate our intelligent search to find suitable subject content or patents.
Select sections of text to find matching patents with Artificial Intelligence. powered by
Select sections of text to find additional relevant content using AI-assisted search. powered by
Abstract
[4,6,8]
is just shorthand for the expression 4:(6:(8:[]))
. So, every list can be written using :
and []
. In fact, every list can be written using :
and []
in just one way. That fact is what makes pattern matching work on lists. Given a list l and a pattern p built using variables, []
, :
and literals, there is at most one way to match p against l. That match gives values to the variables in p. It might not match, if p requires a list that’s longer than l, or if p contains a literal that doesn’t match the value in the corresponding position in l.