Introduction to lambda expression & lambda calculus

Download Introduction to lambda expression & lambda calculus

Post on 17-Jul-2015




2 download

Embed Size (px)


<ul><li><p>RequirementsCommon Knowledge of ProgrammingMaybe Python/RubyRecursion</p></li><li><p>LAMBDA INTROKIM LEO</p></li><li><p>lambda expressiondef square(x):return x*x=&gt; square = lambda x: x*x</p><p>e.g.:(lambda x: x*x)(8) =&gt;8*8 =&gt;64</p><p>But how could make use of LAMBDA?</p></li><li><p>lambda expressionalist: [8, 5, 2, 4, 62, 4, 6]anOp: blablablaapply the operation to the list.</p><p>like:for i = 0 to len(alist):anOp( alist[i] )or:foreach i in alist:anOp( i )</p></li><li><p>Implementapply_square_for_each(alist):foreach i in alist: square( i );apply_plusplus7_for_each(alist):foreach i in alist: plusplus7( i );</p><p>apply_for_each(alist, op):casewhen op == "square":foreach i in alist: square( i ).....</p></li><li><p>lambda expressionapply_for_each(alist, alambda):foreach i in alist:alambda( i )</p><p>apply_for_each([1,2,3], square)apply_for_each([ ... ], anything_you_want_applied_to)</p><p>apply_for_each =&gt; map/each</p></li><li><p>General LISt ProcessingMap[x,y,z] -&gt; map(op,[x,y,z]) =&gt; [op(x),op(y),op(z)]Reduce[x,y,z] -&gt; reduce(op,[x,y,z],v) =&gt; op(op(op(v,x),y),z)Filter[x,y,z] -&gt; filter(op,[x,y,z]) =&gt; a subset of the list for each op(i) =&gt; true</p></li><li><p>more..each, find, every/all, any/some, invoke, where, sort, group/groupBy, countBy.... (underscore.js/Ruby Enumerable Module)</p><p>var all_of_usdef lonelyboydef lonelygirlzip( filter( lonelyboy, all_of_us), filter( lonelygirl, all_of_us) )</p></li><li><p>Lambda Calculuslambda x: x</p><p>lambda x,y: y(x)</p><p>(lambda x:x)(1)</p><p>1</p></li><li><p>RecursionY := g.(x.g (x x)) (x.g (x x))Y f=&gt; g.(x.g (x x)) (x.g (x x)) f=&gt; (x.f (x x)) (x.f (x x))=&gt; f ((x.f (x x)) (x.f (x x)))=&gt; f (Y f)</p></li><li><p>SKI CombinatorI := x.xK := x.y.xS := x.y.z.x z (y z)</p><p>OR:</p><p>Ix = xKxy = xSxyz = xz(yz)</p></li><li><p>self-applicationSII = I(I) = </p><p>SII(SII)= I(SII)(I(SII))= I(SII)(SII)= SII(SII)</p></li><li><p>reverseS(K(SI))K K(SI)(K) SI(K) I(K) I</p></li><li><p>Y in SKIY = S (K (S I I)) (S (S (K S) K) (K (S I I)))Y' = S S K (S (K (S S (S (S S K)))) K)</p></li></ul>