Slide 1

Slide 1 text

www.karakun.com Rock-solid JavaScript through Applied Science Prof. Dierk König

Slide 2

Slide 2 text

2 Dierk König Fellow at Karakun Prof at FHNW @mittie @ProfDKoenig https://dierk.github.io/Home

Slide 3

Slide 3 text

3 Oxymoron JavaScript and Rock-solid JavaScript and Applied Science

Slide 4

Slide 4 text

4 Computability Turing Machine Lambda Calculus Recursive Functions

Slide 5

Slide 5 text

-BNCEB$BMDVMVT ЋBMQIB3FOBNF1BSBNFUFS 3FGBDUPSJOH  ЌCFUB"QQMZ"SHVNFOU БFUB$BODFM1BSBNFUFS

Slide 6

Slide 6 text

"MQIB5SBOTMBUJPO DPOTUJEYY DPOTUJEZZ

Slide 7

Slide 7 text

#FUB3FEVDUJPO GYG Y  JE    YJE Y    JE   YY    

Slide 8

Slide 8 text

&UB3FEVDUJPO YZQMVT Y  Z  YQMVT Y  QMVT

Slide 9

Slide 9 text

"UPNJD-BNCEB5FSNT // atoms const id = x => x; const fst = x => y => x; const snd = x => y => y;

Slide 10

Slide 10 text

1BJS // atoms const id = x => x; const fst = x => y => x; const snd = x => y => y; const Pair = x => y => accessor => accessor(x)(y);

Slide 11

Slide 11 text

1BJS$SFBUJPO // atoms const id = x => x; const fst = x => y => x; const snd = x => y => y; const Pair = x => y => accessor => accessor(x)(y); const point = Pair(1024)(200);

Slide 12

Slide 12 text

1BJS"DDFTT // atoms const id = x => x; const fst = x => y => x; const snd = x => y => y; const Pair = x => y => accessor => accessor(x)(y); const point = Pair(1024)(200); point(fst); // 1024, compare to pair.fst point(snd); // 200, compare to pair.snd the basic product type

Slide 13

Slide 13 text

5SJQMF $BOZPVFODPEFUSJQMFTCZGPMMPXJOH UIFTBNFQBUUFSOBTGPSQBJST  /5VQMFT

Slide 14

Slide 14 text

5VQMFT6TBHF const [Person, firstname, lastname, age] = Tuple(3); const dierk = Person('Dierk')('König')(51); dierk(firstname); // 'Dierk', compare to dierk.firstname

Slide 15

Slide 15 text

1BJS 5VQMF FUD /PUFUIBUPVSQBUUFSOMFBETUP immutableWBMVFT PCKFDUT  "DDFTTPSGVODUJPOTBSFlazyVOUJM UIFZBSFBQQMJFE CFUBSFEVDFE 

Slide 16

Slide 16 text

&JUIFS $P1SPEVDU 4VN const Left = x => f => g => f(x); // ctor 1 const Right = x => f => g => g(x); // ctor 2 const either = e => f => g => e(f)(g); // accessor const safeDiv = x => y => y === 0 ? Left ("divisor is zero") : Right(x / y); either ( safeDiv(1)(0) ) ( msg => console.log(msg) ) ( res => id(res) ) η-reduce

Slide 17

Slide 17 text

3FGBDUPSJOH"MHFCSB const Left = x => f => g => f(x); // ctor 1 const Right = x => f => g => g(x); // ctor 2 const either = e => f => g => e(f)(g); // accessor const safeDiv = x => y => y === 0 ? Left ("divisor is zero") : Right(x / y); either ( safeDiv(1)(0) ) ( console.log ) ( id ) η-reduce

Slide 18

Slide 18 text

3FGBDUPSJOH"MHFCSB const Left = x => f => g => f(x); // ctor 1 const Right = x => f => g => g(x); // ctor 2 const either = e => f => e(f) ; // accessor const safeDiv = x => y => y === 0 ? Left ("divisor is zero") : Right(x / y); either ( safeDiv(1)(0) ) ( console.log ) ( id ) η-reduce

Slide 19

Slide 19 text

&JUIFS $P1SPEVDU 4VN const Left = x => f => g => f(x); // ctor 1 const Right = x => f => g => g(x); // ctor 2 const either = e => e ; // accessor const safeDiv = x => y => y === 0 ? Left ("divisor is zero") : Right(x / y); either ( safeDiv(1)(0) ) ( console.log ) ( id ) definition

Slide 20

Slide 20 text

&JUIFS $P1SPEVDU 4VN const Left = x => f => g => f(x); // ctor 1 const Right = x => f => g => g(x); // ctor 2 const either = id ; // accessor const safeDiv = x => y => y === 0 ? Left ("divisor is zero") : Right(x / y); either ( safeDiv(1)(0) ) ( console.log ) ( id )

Slide 21

Slide 21 text

&JUIFS .BZCF FUD /PUFUIBUPVSQBUUFSOMFBETUP null-safeDPNQVUBUJPO :PVcannot forgetUPDPWFSBMM DBTFT FHUIFOVMMPSFSSPSDBTF 

Slide 22

Slide 22 text

$IPJDF $BOZPVFODPEFNVMUJQMFDIPJDFTCZ GPMMPXJOHUIFTBNFQBUUFSOBTGPS &JUIFS

Slide 23

Slide 23 text

3FBM8PSMEVTBHF8FC4IPQ1BZNFOU0QUJPOT const [Cash, CreditCard, Transfer, match] = Choice(3); // generalized sum type const pay = payment => match(payment) ( () => amount => 'pay ' + amount + ' cash') ( ( { number, sec } ) => amount => 'pay ' + amount + ' with credit card ' + number + ' / ' + sec) ( ( [ from, to ] ) => amount => 'pay ' + amount + ' by wire from ' + from + ' to ' + to); let payment = Cash(); assert.is( pay(payment)(50), 'pay 50 cash'); payment = CreditCard( { number: '0000 1111 2222 3333', sec: '123' } ); assert.is( pay(payment)(50), 'pay 50 with credit card 0000 1111 2222 3333 / 123'); payment = Transfer(['Account 1', 'Account 2']); assert.is( pay(payment)(50), 'pay 50 by wire from Account 1 to Account 2');

Slide 24

Slide 24 text

24 Rock-solid Science Rock-solid immutable "Objects" Null-safe operations that cover all cases All done with lambda expressions

Slide 25

Slide 25 text

25 Repository https://github.com/Dierk/ BrushUpYourJavaScript

Slide 26

Slide 26 text

26 Credits Gabriel Lebec @g_lebec Daniel Dietrich @danieldietrich

Slide 27

Slide 27 text

27 Further Support Engineering, Consulting, Training Certificate of Advanced Studies

Slide 28

Slide 28 text

Karakun AG Elisabethenanlage 25 4051 Basel Switzerland T. E. W. +41 61 551 36 36 [email protected] www.karakun.com Gerne beraten und schulen wir auch Sie dabei, welche Technologien sie am besten einsetzen und wie sie ihre Software-Entwicklung verbessern können. Wir freuen uns auf Ihre Kontaktaufnahme!