cos 326 func,onal programming: an elegant weapon for the ... · in 1936, alonzo church invented the...
TRANSCRIPT
![Page 1: COS 326 Func,onal Programming: An elegant weapon for the ... · In 1936, Alonzo Church invented the lambda calculus. He called it a logic, but it was a language of pure funcFons --](https://reader033.vdocument.in/reader033/viewer/2022052001/60143e90bce2e00ffb36a49c/html5/thumbnails/1.jpg)
COS326Func,onalProgramming:Anelegantweaponforthemodernage
DavidWalkerPrincetonUniversity
©2007xkcd
slidescopyright2013-2015DavidWalkerandAndrewW.Appelpermissiongrantedtoreusetheseslidesfornon-commercialeducaFonalpurposes
![Page 2: COS 326 Func,onal Programming: An elegant weapon for the ... · In 1936, Alonzo Church invented the lambda calculus. He called it a logic, but it was a language of pure funcFons --](https://reader033.vdocument.in/reader033/viewer/2022052001/60143e90bce2e00ffb36a49c/html5/thumbnails/2.jpg)
In1936,AlonzoChurchinventedthelambdacalculus.Hecalleditalogic,butitwasalanguageofpurefuncFons--theworld'sfirstprogramminglanguage.Hesaid:"Theremay,indeed,beotherapplica3onsofthesystemthanitsuseasalogic."AlonzoChurch,1903-1995
PrincetonProfessor,1929-1967
2
![Page 3: COS 326 Func,onal Programming: An elegant weapon for the ... · In 1936, Alonzo Church invented the lambda calculus. He called it a logic, but it was a language of pure funcFons --](https://reader033.vdocument.in/reader033/viewer/2022052001/60143e90bce2e00ffb36a49c/html5/thumbnails/3.jpg)
In1936,AlonzoChurchinventedthelambdacalculus.Hecalleditalogic,butitwasalanguageofpurefuncFons--theworld'sfirstprogramminglanguage.Hesaid:"Theremay,indeed,beotherapplica3onsofthesystemthanitsuseasalogic."
Greatesttechnologicalunderstatementofthe20th
century?
AlonzoChurch,1903-1995PrincetonProfessor,1929-1967
3
![Page 4: COS 326 Func,onal Programming: An elegant weapon for the ... · In 1936, Alonzo Church invented the lambda calculus. He called it a logic, but it was a language of pure funcFons --](https://reader033.vdocument.in/reader033/viewer/2022052001/60143e90bce2e00ffb36a49c/html5/thumbnails/4.jpg)
AlonzoChurch1934--developedlambdacalculus
AlanTuring(PhDPrinceton1938)1936--developedTuringmachines
ProgrammingLanguages Computers
hZp://press.princeton.edu/chapters/s9780.pdfOp3onalreading:TheBirthofComputerScienceatPrincetoninthe1930sbyAndrewW.Appel,2012.
4
![Page 5: COS 326 Func,onal Programming: An elegant weapon for the ... · In 1936, Alonzo Church invented the lambda calculus. He called it a logic, but it was a language of pure funcFons --](https://reader033.vdocument.in/reader033/viewer/2022052001/60143e90bce2e00ffb36a49c/html5/thumbnails/5.jpg)
AfewdesignersoffuncFonalprogramminglanguages5
AlonzoChurch:λ-calculus,1934
JohnMcCarthy(PhDPrinceton1951)
LISP,1958
GuySteele&GerrySussman:Scheme,1975
RobinMilnerML,1978
XavierLeroy:Ocaml,1990’s
LucaCardelliEdinburghML,1981
StandardML1986
CaML1980s
Appel&MacQueen:SML/NJ,1988
Implementa,ons:
![Page 6: COS 326 Func,onal Programming: An elegant weapon for the ... · In 1936, Alonzo Church invented the lambda calculus. He called it a logic, but it was a language of pure funcFons --](https://reader033.vdocument.in/reader033/viewer/2022052001/60143e90bce2e00ffb36a49c/html5/thumbnails/6.jpg)
Theywereyoungerthantheyappear…6
AlonzoChurch:λ-calculus,1934
JohnMcCarthy(PhDPrinceton1951)
LISP,1958
GuySteele&GerrySussman:Scheme,1975
RobinMilnerML,1978
XavierLeroy:Ocaml,1990’s
LucaCardelliEdinburghML,1981
Appel&MacQueen:SML/NJ,1988
Implementa,ons:Photo~1960
Photo~1975
Photo~2005Photo~1995
Photo2005 Photo~2000
Photo~2005
Photo~1995 Photo~1995
![Page 7: COS 326 Func,onal Programming: An elegant weapon for the ... · In 1936, Alonzo Church invented the lambda calculus. He called it a logic, but it was a language of pure funcFons --](https://reader033.vdocument.in/reader033/viewer/2022052001/60143e90bce2e00ffb36a49c/html5/thumbnails/7.jpg)
VastlyAbbreviatedFPGeneologyLCFTheoremProver(70s)
EdinburghML
Miranda(80s)
Haskell(90s-now)
StandardML(90s-now) OCaml
(90s-now)
Caml(80s-now)
F#(now)
LISP(50s-now)
Scheme(70s-now)
lazy
typed,polymorphic
untyped
Coq(80s-now)
dependentlytyped
call-by-value
Racket(00s-now)
Scala(00s-now)
7
![Page 8: COS 326 Func,onal Programming: An elegant weapon for the ... · In 1936, Alonzo Church invented the lambda calculus. He called it a logic, but it was a language of pure funcFons --](https://reader033.vdocument.in/reader033/viewer/2022052001/60143e90bce2e00ffb36a49c/html5/thumbnails/8.jpg)
ButWhyFuncFonalProgrammingNow?
• FuncFonalprogrammingwillintroduceyoutonewwaystothinkaboutandstructureyourprograms:– newreasoningprinciples– newabstracFons– newdesignpaZerns– newalgorithms– elegantcode
• Technologytrendspointtoincreasingparallelism:– mulFcore,gpu,datacenter– funcFonalprogrammingtechniquessuchasmap-reduceprovideaplausiblewayforwardformanyapplicaFons
8
![Page 9: COS 326 Func,onal Programming: An elegant weapon for the ... · In 1936, Alonzo Church invented the lambda calculus. He called it a logic, but it was a language of pure funcFons --](https://reader033.vdocument.in/reader033/viewer/2022052001/60143e90bce2e00ffb36a49c/html5/thumbnails/9.jpg)
FuncFonalLanguages:Who’susingthem?
F#inVisualStudio
map-reduceintheirdatacenters
Erlangforconcurrency,HaskellformanagingPHP
Haskelltosynthesizehardware
Scalaforcorrectness,maintainability,flexibility
www.arFma.com/scalazine/arFcles/twiZer_on_scala.htmlgregosuri.com/how-facebook-uses-erlang-for-real-Fme-chatwww.janestcapital.com/technology/ocaml.phpmsdn.microsos.com/en-us/fsharp/cc742182labs.google.com/papers/mapreduce.htmlwww.haskell.org/haskellwiki/Haskell_in_industry
HaskellforspecifyingequityderivaFves
mathemaFcians
Coq(re)proofof4-colortheorem
9
![Page 10: COS 326 Func,onal Programming: An elegant weapon for the ... · In 1936, Alonzo Church invented the lambda calculus. He called it a logic, but it was a language of pure funcFons --](https://reader033.vdocument.in/reader033/viewer/2022052001/60143e90bce2e00ffb36a49c/html5/thumbnails/10.jpg)
FuncFonalLanguages:Jointhecrowd• ElementsoffuncFonalprogrammingareshowingupallover
– F#inMicrososVisualStudio– ScalacombinesML(afuncFonallanguage)withObjects
• runsontheJVM– C#includes“delegates”
• delegates==funcFons– Pythonincludes“lambdas”
• lambdas==morefuncFons– Javascript
• findtutorialsonlineaboutusingfuncFonalprogrammingtechniquestowritemoreelegantcode
– C++librariesformap-reduce• enabledfuncFonalparallelismatGoogle
– JavahasgenericsandGC– ...
10
![Page 11: COS 326 Func,onal Programming: An elegant weapon for the ... · In 1936, Alonzo Church invented the lambda calculus. He called it a logic, but it was a language of pure funcFons --](https://reader033.vdocument.in/reader033/viewer/2022052001/60143e90bce2e00ffb36a49c/html5/thumbnails/11.jpg)
COURSELOGISTICS
11
![Page 12: COS 326 Func,onal Programming: An elegant weapon for the ... · In 1936, Alonzo Church invented the lambda calculus. He called it a logic, but it was a language of pure funcFons --](https://reader033.vdocument.in/reader033/viewer/2022052001/60143e90bce2e00ffb36a49c/html5/thumbnails/12.jpg)
CourseStaff
ChristopherMoreyTeachingFacultyHeadPreceptoroffice:COS208email:cmorey@
RobinQiuGradStudentoffice:Fishbowlemail:yqiu@cs
AndersMiltnerGradStudentoffice:Fishbowl
email:amiltner@cs
DavidWalkerProfessor
office:COS211email:dpw@
12
![Page 13: COS 326 Func,onal Programming: An elegant weapon for the ... · In 1936, Alonzo Church invented the lambda calculus. He called it a logic, but it was a language of pure funcFons --](https://reader033.vdocument.in/reader033/viewer/2022052001/60143e90bce2e00ffb36a49c/html5/thumbnails/13.jpg)
Resources• Web:
– hZp://www.cs.princeton.edu/~cos326
• Lecturescheduleandreadings:– $(coursehome)/lectures.php
• Assignments:– $(coursehome)/assignments.php
• Precepts– usefulifyouwanttodowellonexamsandhomeworks
• InstallOCaml:$(coursehome)/resources.php
13
![Page 14: COS 326 Func,onal Programming: An elegant weapon for the ... · In 1936, Alonzo Church invented the lambda calculus. He called it a logic, but it was a language of pure funcFons --](https://reader033.vdocument.in/reader033/viewer/2022052001/60143e90bce2e00ffb36a49c/html5/thumbnails/14.jpg)
CollaboraFonPolicyTheCOS326collaboraFonpolicycanbefoundhere:
Readitinfullpriortobeginningthefirstassignment.PleaseaskquesFonswheneveranythingisunclear,atanyFmeduringthecourse.
hZp://www.cs.princeton.edu/courses/archive/fall13/cos326/info.php#collab
14
![Page 15: COS 326 Func,onal Programming: An elegant weapon for the ... · In 1936, Alonzo Church invented the lambda calculus. He called it a logic, but it was a language of pure funcFons --](https://reader033.vdocument.in/reader033/viewer/2022052001/60143e90bce2e00ffb36a49c/html5/thumbnails/15.jpg)
CourseTextbook
hZp://realworldocaml.org/
15
![Page 16: COS 326 Func,onal Programming: An elegant weapon for the ... · In 1936, Alonzo Church invented the lambda calculus. He called it a logic, but it was a language of pure funcFons --](https://reader033.vdocument.in/reader033/viewer/2022052001/60143e90bce2e00ffb36a49c/html5/thumbnails/16.jpg)
FinalExamTherewillbeamidtermexam,inmidtermweekWednesday,October26
Therewillbeafinalexam,inexamperiod(January—Makeyourtravelplansaccordingly)
16
![Page 17: COS 326 Func,onal Programming: An elegant weapon for the ... · In 1936, Alonzo Church invented the lambda calculus. He called it a logic, but it was a language of pure funcFons --](https://reader033.vdocument.in/reader033/viewer/2022052001/60143e90bce2e00ffb36a49c/html5/thumbnails/17.jpg)
Assignment0
FigureouthowtodownloadandinstallOCaml4.03onyourmachinebytheFmepreceptbeginstomorrow.
(or,howtouseOCamlbysshtoPrincetonUniversityservers)
ResourcesPage:
hZp://www.cs.princeton.edu/courses/archive/fall15/cos326/resources.php
Hint:
ocaml.org
17
![Page 18: COS 326 Func,onal Programming: An elegant weapon for the ... · In 1936, Alonzo Church invented the lambda calculus. He called it a logic, but it was a language of pure funcFons --](https://reader033.vdocument.in/reader033/viewer/2022052001/60143e90bce2e00ffb36a49c/html5/thumbnails/18.jpg)
PublicServiceAnnouncement
ThePenisMighterthantheKeyboard:AdvantagesofLonghandOverLaptopNoteTaking
PamMueller(PrincetonUniversity)
DanielOppenheimer(UCLA)JournalofPsychologicalScience,June2014,vol25,no6
hZp://pss.sagepub.com/content/25/6/1159.fullkeytype=ref&siteid=sppss&ijkey=CjRAwmrlURGNw
• YoulearnconceptualtopicsbeZerbytakingnotesbyhand.• FacebookandWorldofWarcrasdistractyourclassmates.
18