learning to love type systems
play

Learning to Love Type Systems Swipe Left, Uncaught TypeError - PowerPoint PPT Presentation

Learning to Love Type Systems: Swipe Left, Uncaught TypeError sugarpirate_ poteto Learning to Love Type Systems Swipe Left, Uncaught TypeError PRESENTED BY Lauren Tan (she/her) Cinemagraph by /u/orbojunglist QCon SF 2018


  1. Learning to Love Type Systems: Swipe Left, Uncaught TypeError Curry–Howard–Lambek correspondence QCon SF 2018

  2. Learning to Love Type Systems: Swipe Left, Uncaught TypeError Stop with the jargon, Lauren QCon SF 2018

  3. Learning to Love Type Systems: Swipe Left, Uncaught TypeError Stop with the jargon, Lauren QCon SF 2018

  4. Learning to Love Type Systems: Swipe Left, Uncaught TypeError declare function Addition(x: number, y: number) : number; �/0 proposition function add(x: number, y: number) : number { return x + y; } �/0 proof QCon SF 2018

  5. Learning to Love Type Systems: Swipe Left, Uncaught TypeError Proposition: If x and y are numbers, a number exists declare function Addition(x: number, y: number) : number; �/0 proposition function add(x: number, y: number) : number { return x + y; } �/0 proof QCon SF 2018

  6. Learning to Love Type Systems: Swipe Left, Uncaught TypeError Proposition: If x and y are numbers, a number exists declare function Addition(x: number, y: number) : number; �/0 proposition function add(x: number, y: number) : number { return x + y; } �/0 proof Proof: x + y proves that a number exists QCon SF 2018

  7. Learning to Love Type Systems: Swipe Left, Uncaught TypeError What is a function? QCon SF 2018

  8. Learning to Love Type Systems: Swipe Left, Uncaught TypeError f : A → B f a : A b : B QCon SF 2018

  9. Learning to Love Type Systems: Swipe Left, Uncaught TypeError f �:; function from type A to type B f an object * of type B an object * of type A * not a JS object QCon SF 2018

  10. Learning to Love Type Systems: Swipe Left, Uncaught TypeError Types are propositions Programs are proofs Curry-Howard Correspondence QCon SF 2018

  11. Learning to Love Type Systems: Swipe Left, Uncaught TypeError Let the type system suggest the implementation QCon SF 2018

  12. Learning to Love Type Systems: Swipe Left, Uncaught TypeError function head<T>(list: T[]) : T { �/0 ��../ } QCon SF 2018

  13. Learning to Love Type Systems: Swipe Left, Uncaught TypeError [ts] Type 'T[]' is not assignable to type 'T'. (parameter) list: T[] function head<T>(list: T[]) : T { return list; } QCon SF 2018

  14. Learning to Love Type Systems: Swipe Left, Uncaught TypeError function head<T>(list: T[]) : T { return list[0]; } QCon SF 2018

  15. Learning to Love Type Systems: Swipe Left, Uncaught TypeError function map<A, B>(fn: (item: A) �=? B, items: A[]) : B[] { �/0 ��../ } QCon SF 2018

  16. Learning to Love Type Systems: Swipe Left, Uncaught TypeError [ts] Type 'A[]' is not assignable to type 'B[]'. Type 'A' is not assignable to type 'B'. (parameter) items: A[] function map<A, B>(fn: (item: A) �=? B, items: A[]) : B[] { return items; } QCon SF 2018

  17. Learning to Love Type Systems: Swipe Left, Uncaught TypeError [ts] Type 'B' is not assignable to type 'B[]'. (parameter) fn: (item: A) �=? B function map<A, B>(fn: (item: A) �=? B, items: A[]) : B[] { return fn(items[0]); } QCon SF 2018

  18. Learning to Love Type Systems: Swipe Left, Uncaught TypeError function map<A, B>(fn: (item: A) �=? B, items: A[]) : B[] { return items.reduce((acc, curr) �=? { acc.push(fn(curr)); return acc; }, [] as B[]); } QCon SF 2018

  19. Learning to Love Type Systems: Swipe Left, Uncaught TypeError myStatelessComponent �:; Props �-? React.ReactNode QCon SF 2018

  20. Learning to Love Type Systems: Swipe Left, Uncaught TypeError [ts] Type '1' is not assignable to type 'StatelessComponent<MyProps>'. const MyStatelessComponent: React.StatelessComponent<MyProps> const MyStatelessComponent: React.SFC<MyProps> = 1; QCon SF 2018

  21. Learning to Love Type Systems: Swipe Left, Uncaught TypeError [ts] Type '() �=? number' is not assignable to type 'StatelessComponent<MyProps>'. Type 'number' is not assignable to type 'ReactElement<any>'. const MyStatelessComponent: React.StatelessComponent<MyProps> const MyStatelessComponent: React.SFC<MyProps> = () �=? 1; QCon SF 2018

  22. Learning to Love Type Systems: Swipe Left, Uncaught TypeError const MyStatelessComponent: React.SFC<MyProps> = props �=? <div> ��../�<0 div>; QCon SF 2018

  23. Learning to Love Type Systems: Swipe Left, Uncaught TypeError Writing better functions QCon SF 2018

  24. Learning to Love Type Systems: Swipe Left, Uncaught TypeError f ( x ) = x 2 QCon SF 2018

  25. Learning to Love Type Systems: Swipe Left, Uncaught TypeError f ( x ) = x 2 Domain Codomain 1 1 2 4 3 9 4 16 5 25 6 36 ��../ ��../ QCon SF 2018

  26. Learning to Love Type Systems: Swipe Left, Uncaught TypeError Total vs Partial functions QCon SF 2018

  27. Learning to Love Type Systems: Swipe Left, Uncaught TypeError Total Partial Impure & Total Impure & Partial Impure Pure & Total Pure & Partial Pure QCon SF 2018

  28. Learning to Love Type Systems: Swipe Left, Uncaught TypeError A partial function is a function Partial that is not defined for all possible input values. QCon SF 2018

  29. Learning to Love Type Systems: Swipe Left, Uncaught TypeError const half = x �=? x / 2; QCon SF 2018

  30. Learning to Love Type Systems: Swipe Left, Uncaught TypeError const half = x �=? x / 2; Possible Domains Possible Codomains number number string NaN void Uncaught TypeError object array symbol QCon SF 2018

  31. Learning to Love Type Systems: Swipe Left, Uncaught TypeError const half = x �=? x / 2; Possible Domains Possible Codomains number number string NaN void Uncaught TypeError object array symbol QCon SF 2018

  32. Learning to Love Type Systems: Swipe Left, Uncaught TypeError const half = x �=? x / 2; Possible Domains Possible Codomains number number string NaN void Uncaught TypeError object array symbol QCon SF 2018

  33. Learning to Love Type Systems: Swipe Left, Uncaught TypeError const half = x �=? x / 2; Possible Domains Possible Codomains 路 half('10') �/0 5 number number half('hello world') �/0 NaN string NaN void Uncaught TypeError object array symbol QCon SF 2018

  34. Learning to Love Type Systems: Swipe Left, Uncaught TypeError QCon SF 2018

  35. Learning to Love Type Systems: Swipe Left, Uncaught TypeError const half = x �=? x / 2; Possible Domains Possible Codomains number number string NaN void Uncaught TypeError object array symbol QCon SF 2018

  36. Learning to Love Type Systems: Swipe Left, Uncaught TypeError const half = x �=? x / 2; Possible Domains Possible Codomains number number string NaN void Uncaught TypeError object array symbol QCon SF 2018

Recommend


More recommend