 	return { l in foldr({ f($0) + $1 })([])(l) }
 }
 
+/// Concatenate a list of lists.
+public func concat<A>(xss : List<List<A>>) -> List<A> {
+	return foldr({ $0 + $1 })(List())(xss)
+}
+
+/// Map a function over a list and concatenate the results.
+public func concatMap<A, B>(f : A -> List<B>) -> List<A> -> List<B> {
+	return { l in foldr({ f($0) + $1 })(List())(l) }
+}
+
 /// Returns the maximum value in a list of comparable values.
 public func maximum<A : Comparable>(l : [A]) -> A {
 	assert(l.count != 0, "Cannot find the maximum value of an empty list.")

public func foldr<A, B>(k: A -> B -> B) -> B -> [A] -> B {
	return { z in { l in
		switch match(l) {
			case .Empty:
				return z
			case .Cons(let x, let xs):
				return k(x)(foldr(k)(z)(xs))

	return { l in and(l.map(p)) }
}

/// Maps a predicate over a list.  For the result to be true, the predicate must be satisfied at
/// least once by an element of the list.
public func any<A>(p : A -> Bool) -> List<A> -> Bool {
	return { l in or(l.map(p)) }
}

/// Maps a predicate over a list.  For the result to be true, the predicate must be satisfied by
/// all elemenets of the list.
public func all<A>(p : A -> Bool) -> List<A> -> Bool {
	return { l in and(l.map(p)) }
}

/// Concatenate a list of lists.
public func concat<A>(xss : [[A]]) -> [A] {
	return foldr({ $0 + $1 })([])(xss)
