Kind/book/List.fold.kind2
2024-02-13 15:30:53 -03:00

36 lines
751 B
Plaintext

List.fold
: ∀(T: *)
∀(list: (List T))
(List.Folder T)
= λT λlist
λP λcons λnil
let fold_P = λxs(P)
let fold_cons = λhead λtail (cons head ((List.fold T tail) P cons nil))
let fold_nil = nil
(~list fold_P fold_cons fold_nil)
// old version:
//List.fold
//: ∀(T: *)
//∀(list: (List T))
//(List.Folder T)
//= λT λlist
//λP λcons λnil
//(~list λxs(P)
//λhead λtail (cons head ((List.fold T tail) P cons nil))
//nil)
// non-fusible version:
//List.fold
//: ∀(T: *)
//∀(list: (List T))
//(List.Folder T)
//= λT λlist
//let P = λxs(List.Folder T)
//let cons = λhead λtail (List.Folder.cons T head (List.fold T tail))
//let nil = (List.Folder.nil T)
//(~list P cons nil)