X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?a=blobdiff_plain;f=arithmetic.mdwn;h=beedc2874eeaa662e21006803bf59321567cbce3;hb=6dcf7995023877c6946a45657126ead9266dcb40;hp=bc15ae8de777a3ad40fe126cbe7500f02edd4890;hpb=cbb48495bd8cd6cdcbebd1bcd8c3051148c8b0a6;p=lambda.git diff --git a/arithmetic.mdwn b/arithmetic.mdwn index bc15ae8d..beedc287 100644 --- a/arithmetic.mdwn +++ b/arithmetic.mdwn @@ -37,15 +37,31 @@ Here are a bunch of pre-tested operations for the untyped lambda calculus. In so let make_list = \h t f z. f h (t f z) in let isempty = \lst. lst (\h sofar. false) true in let head = \lst. lst (\h sofar. h) junk in - let tail = \lst. (\shift lst. lst shift (make_pair empty junk) get_2nd) + let tail_empty = empty in + let tail = \lst. (\shift. lst shift (make_pair empty tail_empty) get_2nd) ; where shift is (\h p. p (\t y. make_pair (make_list h t) t)) in let length = \lst. lst (\h sofar. succ sofar) 0 in let map = \f lst. lst (\h sofar. make_list (f h) sofar) empty in let filter = \f lst. lst (\h sofar. f h (make_list h sofar) sofar) empty in ; or let filter = \f lst. lst (\h. f h (make_list h) I) empty in - let reverse = \lst. lst (\h t. t make_list (\f n. f h n)) empty in - + + ; append list2 to list1 with: list1 make_list list2 + let singleton = \x f z. f x z in + let reverse = \lst. lst (\h sofar. sofar make_list (singleton h)) empty in + ; zip [a;b;c] [x; y; z] ~~> [(a,x);(b,y);(c,z)] + let zip = \left right. (\base build. reverse left build base (\x y. reverse x)) + ; where base is + (make_pair empty (map (\h u. u h) right)) + ; and build is + (\h sofar. sofar (\x y. isempty y + sofar + (make_pair (make_list (\u. head y (u h)) x) (tail y)) + )) in + + let all = \f lst. lst (\h sofar. and sofar (f h)) true in + let any = \f lst. lst (\h sofar. or sofar (f h)) false in + ; version 1 lists