Upload
others
View
3
Download
0
Embed Size (px)
Citation preview
COS326Func,onalProgramming:Anelegantweaponforthemodernage
DavidWalkerPrincetonUniversity
©2007xkcd
slidescopyright2013-2015DavidWalkerandAndrewW.Appelpermissiongrantedtoreusetheseslidesfornon-commercialeducaFonalpurposes
In1936,AlonzoChurchinventedthelambdacalculus.Hecalleditalogic,butitwasalanguageofpurefuncFons--theworld'sfirstprogramminglanguage.Hesaid:"Theremay,indeed,beotherapplica3onsofthesystemthanitsuseasalogic."AlonzoChurch,1903-1995
PrincetonProfessor,1929-1967
2
In1936,AlonzoChurchinventedthelambdacalculus.Hecalleditalogic,butitwasalanguageofpurefuncFons--theworld'sfirstprogramminglanguage.Hesaid:"Theremay,indeed,beotherapplica3onsofthesystemthanitsuseasalogic."
Greatesttechnologicalunderstatementofthe20th
century?
AlonzoChurch,1903-1995PrincetonProfessor,1929-1967
3
AlonzoChurch1934--developedlambdacalculus
AlanTuring(PhDPrinceton1938)1936--developedTuringmachines
ProgrammingLanguages Computers
hZp://press.princeton.edu/chapters/s9780.pdfOp3onalreading:TheBirthofComputerScienceatPrincetoninthe1930sbyAndrewW.Appel,2012.
4
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:
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
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
ButWhyFuncFonalProgrammingNow?
• FuncFonalprogrammingwillintroduceyoutonewwaystothinkaboutandstructureyourprograms:– newreasoningprinciples– newabstracFons– newdesignpaZerns– newalgorithms– elegantcode
• Technologytrendspointtoincreasingparallelism:– mulFcore,gpu,datacenter– funcFonalprogrammingtechniquessuchasmap-reduceprovideaplausiblewayforwardformanyapplicaFons
8
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
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
COURSELOGISTICS
11
CourseStaff
ChristopherMoreyTeachingFacultyHeadPreceptoroffice:COS208email:cmorey@
RobinQiuGradStudentoffice:Fishbowlemail:yqiu@cs
AndersMiltnerGradStudentoffice:Fishbowl
email:amiltner@cs
DavidWalkerProfessor
office:COS211email:dpw@
12
Resources• Web:
– hZp://www.cs.princeton.edu/~cos326
• Lecturescheduleandreadings:– $(coursehome)/lectures.php
• Assignments:– $(coursehome)/assignments.php
• Precepts– usefulifyouwanttodowellonexamsandhomeworks
• InstallOCaml:$(coursehome)/resources.php
13
CollaboraFonPolicyTheCOS326collaboraFonpolicycanbefoundhere:
Readitinfullpriortobeginningthefirstassignment.PleaseaskquesFonswheneveranythingisunclear,atanyFmeduringthecourse.
hZp://www.cs.princeton.edu/courses/archive/fall13/cos326/info.php#collab
14
CourseTextbook
hZp://realworldocaml.org/
15
FinalExamTherewillbeamidtermexam,inmidtermweekWednesday,October26
Therewillbeafinalexam,inexamperiod(January—Makeyourtravelplansaccordingly)
16
Assignment0
FigureouthowtodownloadandinstallOCaml4.03onyourmachinebytheFmepreceptbeginstomorrow.
(or,howtouseOCamlbysshtoPrincetonUniversityservers)
ResourcesPage:
hZp://www.cs.princeton.edu/courses/archive/fall15/cos326/resources.php
Hint:
ocaml.org
17
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