├── EPS-ADTs.ppt ├── EPS-Adversity.ppt ├── EPS-Arrays.ppt ├── EPS-Concurrency1.ppt ├── EPS-Concurrency2.ppt ├── EPS-Failures.pptx ├── EPS-Final.ppt ├── EPS-Forth.ppt ├── EPS-FunctionObjects.ppt ├── EPS-FunkComposition.ppt ├── EPS-Funks.ppt ├── EPS-Imperative.ppt ├── EPS-Interactivity.pptx ├── EPS-Intro.ppt ├── EPS-ItersGensCorouts.ppt ├── EPS-Lambda.ppt ├── EPS-LambdaInPython.ppt ├── EPS-Monads.ppt ├── EPS-OOP-Frameworks.ppt ├── EPS-OOP-JavaScript.ppt ├── EPS-OOP-Smalltalk.ppt ├── EPS-OOP.ppt ├── EPS-OOPBasics.pptx ├── EPS-Plugins.ppt ├── EPS-Reflection.pptx ├── EPS-SQL-Spreadsheets.ppt ├── EPS-TuringMachines.ppt ├── EPS-Types.pptx ├── LICENSE.txt ├── Maybe.cs ├── README.md ├── lambda.py └── monads.py /EPS-ADTs.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crista/EPS-slides/8cf117976ba0244428c6bddb732091df59e55930/EPS-ADTs.ppt -------------------------------------------------------------------------------- /EPS-Adversity.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crista/EPS-slides/8cf117976ba0244428c6bddb732091df59e55930/EPS-Adversity.ppt -------------------------------------------------------------------------------- /EPS-Arrays.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crista/EPS-slides/8cf117976ba0244428c6bddb732091df59e55930/EPS-Arrays.ppt -------------------------------------------------------------------------------- /EPS-Concurrency1.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crista/EPS-slides/8cf117976ba0244428c6bddb732091df59e55930/EPS-Concurrency1.ppt -------------------------------------------------------------------------------- /EPS-Concurrency2.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crista/EPS-slides/8cf117976ba0244428c6bddb732091df59e55930/EPS-Concurrency2.ppt -------------------------------------------------------------------------------- /EPS-Failures.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crista/EPS-slides/8cf117976ba0244428c6bddb732091df59e55930/EPS-Failures.pptx -------------------------------------------------------------------------------- /EPS-Final.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crista/EPS-slides/8cf117976ba0244428c6bddb732091df59e55930/EPS-Final.ppt -------------------------------------------------------------------------------- /EPS-Forth.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crista/EPS-slides/8cf117976ba0244428c6bddb732091df59e55930/EPS-Forth.ppt -------------------------------------------------------------------------------- /EPS-FunctionObjects.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crista/EPS-slides/8cf117976ba0244428c6bddb732091df59e55930/EPS-FunctionObjects.ppt -------------------------------------------------------------------------------- /EPS-FunkComposition.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crista/EPS-slides/8cf117976ba0244428c6bddb732091df59e55930/EPS-FunkComposition.ppt -------------------------------------------------------------------------------- /EPS-Funks.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crista/EPS-slides/8cf117976ba0244428c6bddb732091df59e55930/EPS-Funks.ppt -------------------------------------------------------------------------------- /EPS-Imperative.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crista/EPS-slides/8cf117976ba0244428c6bddb732091df59e55930/EPS-Imperative.ppt -------------------------------------------------------------------------------- /EPS-Interactivity.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crista/EPS-slides/8cf117976ba0244428c6bddb732091df59e55930/EPS-Interactivity.pptx -------------------------------------------------------------------------------- /EPS-Intro.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crista/EPS-slides/8cf117976ba0244428c6bddb732091df59e55930/EPS-Intro.ppt -------------------------------------------------------------------------------- /EPS-ItersGensCorouts.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crista/EPS-slides/8cf117976ba0244428c6bddb732091df59e55930/EPS-ItersGensCorouts.ppt -------------------------------------------------------------------------------- /EPS-Lambda.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crista/EPS-slides/8cf117976ba0244428c6bddb732091df59e55930/EPS-Lambda.ppt -------------------------------------------------------------------------------- /EPS-LambdaInPython.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crista/EPS-slides/8cf117976ba0244428c6bddb732091df59e55930/EPS-LambdaInPython.ppt -------------------------------------------------------------------------------- /EPS-Monads.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crista/EPS-slides/8cf117976ba0244428c6bddb732091df59e55930/EPS-Monads.ppt -------------------------------------------------------------------------------- /EPS-OOP-Frameworks.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crista/EPS-slides/8cf117976ba0244428c6bddb732091df59e55930/EPS-OOP-Frameworks.ppt -------------------------------------------------------------------------------- /EPS-OOP-JavaScript.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crista/EPS-slides/8cf117976ba0244428c6bddb732091df59e55930/EPS-OOP-JavaScript.ppt -------------------------------------------------------------------------------- /EPS-OOP-Smalltalk.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crista/EPS-slides/8cf117976ba0244428c6bddb732091df59e55930/EPS-OOP-Smalltalk.ppt -------------------------------------------------------------------------------- /EPS-OOP.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crista/EPS-slides/8cf117976ba0244428c6bddb732091df59e55930/EPS-OOP.ppt -------------------------------------------------------------------------------- /EPS-OOPBasics.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crista/EPS-slides/8cf117976ba0244428c6bddb732091df59e55930/EPS-OOPBasics.pptx -------------------------------------------------------------------------------- /EPS-Plugins.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crista/EPS-slides/8cf117976ba0244428c6bddb732091df59e55930/EPS-Plugins.ppt -------------------------------------------------------------------------------- /EPS-Reflection.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crista/EPS-slides/8cf117976ba0244428c6bddb732091df59e55930/EPS-Reflection.pptx -------------------------------------------------------------------------------- /EPS-SQL-Spreadsheets.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crista/EPS-slides/8cf117976ba0244428c6bddb732091df59e55930/EPS-SQL-Spreadsheets.ppt -------------------------------------------------------------------------------- /EPS-TuringMachines.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crista/EPS-slides/8cf117976ba0244428c6bddb732091df59e55930/EPS-TuringMachines.ppt -------------------------------------------------------------------------------- /EPS-Types.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crista/EPS-slides/8cf117976ba0244428c6bddb732091df59e55930/EPS-Types.pptx -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | https://creativecommons.org/licenses/by-sa/4.0/ 2 | -------------------------------------------------------------------------------- /Maybe.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public interface Maybe{} 4 | 5 | public class Nothing : Maybe 6 | { 7 | public override string ToString() 8 | { 9 | return "Nothing"; 10 | } 11 | } 12 | 13 | public class Something : Maybe 14 | { 15 | public T Value { get; private set; } 16 | public Something (T value) 17 | { 18 | Value = value; 19 | } 20 | public override string ToString() 21 | { 22 | return Value.ToString(); 23 | } 24 | } 25 | 26 | public static class MaybeMonad 27 | { 28 | public static Maybe ToMaybe(this T value) 29 | { 30 | return new Something(value); 31 | } 32 | 33 | public static Maybe Bind(this Maybe a, 34 | Func> func) 35 | { 36 | var something = a as Something; 37 | return something == null ? 38 | new Nothing() : 39 | func(something.Value); 40 | } 41 | } 42 | 43 | public static class Extensions 44 | { 45 | public static Maybe Div(this int numerator, int denominator) 46 | { 47 | return denominator == 0 48 | ? (Maybe)new Nothing() 49 | : new Something(numerator/denominator); 50 | } 51 | } 52 | 53 | class MainClass { 54 | public static void Main (string[] args) { 55 | Console.WriteLine (3.ToMaybe()); 56 | Console.WriteLine ("Hello World".ToMaybe()); 57 | Console.WriteLine (15.Div(3)); 58 | Console.WriteLine (15.Div(3).Bind(n => Extensions.Div(n, 0))); 59 | Console.WriteLine (36.ToMaybe().Bind(n => Extensions.Div(n, 3)).Bind(m => Extensions.Div(m, 0)).Bind(p => Extensions.Div(p, 9))); 60 | } 61 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EPS-slides 2 | -------------------------------------------------------------------------------- /lambda.py: -------------------------------------------------------------------------------- 1 | VOID = lambda x: x 2 | # or, for debugging 3 | def VOID(_): 4 | raise Exception('VOID cannot be called') 5 | 6 | # Booleans and conditionals 7 | IF = lambda c: lambda t: lambda f: c(t)(f) 8 | TRUE = lambda t: lambda f: t 9 | FALSE = lambda t: lambda f: f 10 | print (IF (TRUE) ("true") ("false")) 11 | print (IF (FALSE) ("true") ("false")) 12 | 13 | # Numbers and arithmetic 14 | ZERO = lambda f: lambda x: x 15 | ONE = lambda f: lambda x: f(x) 16 | TWO = lambda f: lambda x: f(f(x)) 17 | THREE = lambda f: lambda x: f(f(f(x))) 18 | FOUR = lambda f: lambda x: f(f(f(f(x)))) 19 | FIVE = lambda f: lambda x: f(f(f(f(f(x))))) 20 | SIX = lambda f: lambda x: f(f(f(f(f(f(x)))))) 21 | # Helpers 22 | def numeral(n): 23 | return lambda f: lambda x: x if n==0 else f(numeral(n-1)(f)(x)) 24 | npy = lambda c: c(lambda x: x+1)(0) 25 | 26 | 27 | SUCC = lambda n: lambda f: lambda x: f(n(f)(x)) 28 | ADD = lambda n: lambda m: lambda f: lambda x: n(f)(m(f)(x)) 29 | MUL = lambda n: lambda m: lambda f: lambda x: m(n(f))(x) 30 | # Examples 31 | print (npy(ZERO)) 32 | print (npy(SUCC(ZERO))) 33 | print (npy(SUCC(SUCC(ZERO)))) 34 | ONE = SUCC(ZERO) 35 | TWO = SUCC(ONE) 36 | FOUR = ADD(TWO)(TWO) 37 | SIXTEEN = MUL(FOUR)(FOUR) 38 | print (npy(FOUR)) 39 | print (npy(SIXTEEN)) 40 | 41 | 42 | # Pairs and lists (data structures) 43 | PAIR = lambda a: lambda b: lambda f: f(a)(b) 44 | LEFT = lambda p: p(lambda a: lambda b: a) 45 | RIGHT = lambda p: p(lambda a: lambda b: b) 46 | # Examples 47 | print (LEFT (PAIR ("left") ("right"))) 48 | print (RIGHT (PAIR ("left") ("right"))) 49 | 50 | NIL = lambda onnil: lambda onlist: onnil(VOID) 51 | CONS = (lambda hd: lambda tl: lambda onnil: lambda onlist: onlist(hd)(tl)) 52 | CONSP = lambda l: l (lambda hd: lambda tl: TRUE) (lambda void: FALSE) 53 | NILP = lambda list: list (lambda x: TRUE) (lambda hd: lambda tl: FALSE) 54 | HEAD = lambda list: list (VOID) (lambda hd: lambda tl: hd) 55 | TAIL = lambda list: list (VOID) (lambda hd: lambda tl: tl) 56 | # Examples 57 | print (IF (NILP(NIL)) ("nil") ("not nil")) 58 | print (IF (NILP(CONS(10)(20))) ("nil") ("not nil")) 59 | print (IF (CONSP(CONS(10)(20))) (lambda x: "cons") (lambda x: "nil")) 60 | print (HEAD (CONS ("head") ("tail"))) 61 | print (TAIL (CONS ("head") ("tail"))) 62 | 63 | 64 | # Combinators and recursion 65 | # Example of recursive function: 66 | factorial = lambda n: 1 if n <= 0 else n*factorial(n-1) 67 | print("factorial(5)=" + str(factorial(5))) 68 | 69 | U = lambda f: f(f) 70 | test = lambda x: "called" 71 | U(test) 72 | # Omega = U(U) # Stack over-flow from infinite loop 73 | 74 | # Example 75 | fact = U(lambda f: lambda n: 1 if n <= 0 else n*(U(f))(n-1)) 76 | print ("fact(5)=" + str(fact(5))) 77 | 78 | # Y combinator 79 | # Y(F) = x such that x = F(x) 80 | # Y(F) = x such that x = F(Y(F)) 81 | # Y(F) = F(Y(F)) 82 | # Y = lambda F: F(Y(F)) # works for call-by-name 83 | 84 | Y = lambda F: F(lambda x: Y(F)(x)) 85 | 86 | fact = Y(lambda f: lambda n: 1 if n <= 0 else n * f(n-1)) 87 | 88 | print (fact(6)) 89 | 90 | # Y combinator, but still calls U by name 91 | Y = U(lambda h: lambda F: F(lambda x: U(h)(F)(x))) 92 | fact = Y(lambda f: lambda n: 1 if n <= 0 else n * f(n-1)) 93 | print (fact(7)) 94 | 95 | # Finally, the best form of the Y combinator, no free variables 96 | Y = (lambda h: lambda F: F(lambda x: h(h)(F)(x)))(lambda h: lambda F: F(lambda x: h(h)(F)(x))) 97 | 98 | fact = Y(lambda f: lambda n: 1 if n <= 0 else n * f(n-1)) 99 | print (fact(8)) 100 | 101 | # fact(5) in pure lambda calculus 102 | R1 = (((lambda f: (((f)((lambda f: ((lambda z: (((f)(((f)(((f)(((f)(((f)(z)))))))))))))))))))((((((lambda y: ((lambda F: (((F)((lambda x: (((((((y)(y)))(F)))(x)))))))))))((lambda y: ((lambda F: (((F)((lambda x: (((((((y)(y)))(F)))(x)))))))))))))((lambda f: ((lambda n: ((((((((((((lambda n: (((((n)((lambda _: ((lambda t: ((lambda f: (((f)((lambda void: (void)))))))))))))((lambda t: ((lambda f: (((t)((lambda void: (void)))))))))))))((((((lambda n: ((lambda m: (((((m)((lambda n: ((lambda f: ((lambda z: (((((((n)((lambda g: ((lambda h: (((h)(((g)(f)))))))))))((lambda u: (z)))))((lambda u: (u)))))))))))))(n)))))))(n)))((lambda f: ((lambda z: (z)))))))))((lambda _: ((((lambda n: (((((n)((lambda _: ((lambda t: ((lambda f: (((f)((lambda void: (void)))))))))))))((lambda t: ((lambda f: (((t)((lambda void: (void)))))))))))))((((((lambda n: ((lambda m: (((((m)((lambda n: ((lambda f: ((lambda z: (((((((n)((lambda g: ((lambda h: (((h)(((g)(f)))))))))))((lambda u: (z)))))((lambda u: (u)))))))))))))(n)))))))((lambda f: ((lambda z: (z)))))))(n)))))))))((lambda _: ((lambda t: ((lambda f: (((f)((lambda void: (void)))))))))))))((lambda _: ((lambda f: ((lambda z: (((f)(z)))))))))))((lambda _: ((((((lambda n: ((lambda m: ((lambda f: ((lambda z: (((((m)(((n)(f)))))(z)))))))))))(n)))(((f)((((((lambda n: ((lambda m: (((((m)((lambda n: ((lambda f: ((lambda z: (((((((n)((lambda g: ((lambda h: (((h)(((g)(f)))))))))))((lambda u: (z)))))((lambda u: (u)))))))))))))(n)))))))(n)))((lambda f: ((lambda z: (((f)(z)))))))))))))))))))))))) 103 | 104 | print (npy(R1)) 105 | -------------------------------------------------------------------------------- /monads.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | def hypotenuse(x, y): 4 | h = math.sqrt(math.pow(x, 2) + math.pow(y, 2)) 5 | return h, "x=" + str(x) + ";y=" + str(y) + "h=" + str(h) 6 | 7 | # Problem: 8 | pow(hypotenuse(6, 16), 4); 9 | 10 | def hypotenuse(x, y): 11 | return math.sqrt(math.pow(x, 2) + math.pow(y, 2)) 12 | 13 | #((float, float) -> float) -> ((float, float) -> (float, string)) 14 | def makeTraceable_f_f(f): 15 | def traceable_f_f(x,y): 16 | h=f(x,y) 17 | return h, str(f) + " was called, result=" + str(h) + "\n" 18 | return traceable_f_f 19 | 20 | # Now let's make one of these! And call it 21 | aTraceableHypo = makeTraceable_f_f(hypotenuse) 22 | aTraceableHypo(3,4) 23 | 24 | # But this still doesn't work: 25 | pow(aTraceableHypo(3,4), 2) 26 | 27 | #(((float, float) -> (float, string)), float) -> 28 | # (((float, float) -> (float, string)) -> (float, string)) 29 | def makeTraceable_f_s_f(f, p): 30 | def traceable_f_s_f(t_f_f): 31 | r = f(t_f_f[0], p) 32 | return r, t_f_f[1] + str(f)+" was called, result="+str(r) + "\n" 33 | return traceable_f_s_f 34 | 35 | # Now let's make one of these! 36 | aTraceablePowOf2=makeTraceable_f_s_f(pow, 2) 37 | 38 | (result,message)=aTraceablePowOf2(aTraceableHypo(3,4)) 39 | print result 40 | print message 41 | 42 | # Let's "bind" them externally instead 43 | # (t, (t->t')) -> t' 44 | def bind(t, f): 45 | return f(t) 46 | 47 | (r, m) = bind(aTraceableHypo(3,4), aTraceablePowOf2) 48 | --------------------------------------------------------------------------------