SlideShare a Scribd company logo
1 of 22
Teaching F#From numerical expressions to 3D graphics Tomáš Petříček F# enthusiast and F# book author PhD student at University of Cambridge
Target audience Freshman students Basic knowledge of math principles(Not too much – they may not like it) Earlier in high-school or later at university should be fine too Possibly first programming course Controversial topic, but F# has many benefits
Related functional textbooks #1 Emphasize theory and abstract thinking
Related functional textbooks #2 Functional programming with fun demos
Why F# as a first language? Mathematically oriented language Supplements math and theory courses  Eliminates differences between students Open-source with cross-platform support  F# for MonoDevelop on Linux/Mac Practical language with some market .NET/Mono skills are valued by industry Very easy transition to C# and other languages
Expressions in F# First functional programming steps
What F# shares with math? Language is exact – we need to precisely say what we want to get Composition does not break things – we can mix various correct facts Things do not change – theorems will always be true, π will not change
Pythagorean theorem Math has equations and expressions Expressions can be evaluated Using F# Interactive > sqrt((pown 3.0 2) + (pown 4.0 2));; val it : float = 5.0
Introducing let declarations and if Solving quadratic equations Script for solving written in F# let d = pown b 2 - 4.0 * a * c;; if d < 0.0 then "No real solution" elifd > 0.0 then "Two solutions" else "One solution";; let x1 = (-b + sqrt d) / 2.0 * a let x2 = (-b - sqrt d) / 2.0 * a;;
DEMO Working with F# expressions
Composing graphics in F# Fun examples for students to play with
Composing graphics Expressions that have drawing as the result Same concepts as mathematical expressions  Basic shapes Functions for creating new shapes > Fun.circle100.0f;; val it : Drawing = (Drawing 100x100) > Fun.fillColorColor.Goldenrod     (Fun.circle 100.0f);; val it : Drawing = (Drawing 100x100)
Composing drawings using custom operator ($) Let declarations to reuse drawings Fun.circle200.0f $  Fun.move 0.0f 150.0f (Fun.circle 100.0f) let plus =    Fun.lineStyle 2.0f Color.SteelBlue     ( Fun.line -10.0f 0.0f 10.0f 0.0f $       Fun.line  0.0f -10.0f 0.0f 10.0f ) let star = plus $ (Fun.rotate 45.0f plus) let bigStar = Fun.scale 2.0f 2.0f star Working with shapes
DEMO Creating drawings using F# expressions
Introducing recursion and 3D Difficult concepts explained using graphics
Explaining recursion Recursion is tricky concept Two types of recursions (from HTDP) Structural – follows recursive data structure For example lists, trees, expressions etc. Such functions must terminate in F# General – arbitrary recursive calls May not terminate (if it is not well written) For example generating fractals
General recursion for lists Not tail-recursive list length Easy visualization of execution Not tail-recursive – work done on the “way back” let rec length list =      match list with      | [] -> 0     | head::tail -> (length tail) + 1
General recursion for lists Tail-recursive list length All work done on the way “forward” This is what tail-recursive means! let rec length acc list =      match list with      | head::tail ->          let newacc = acc + 1 in length newacc tail     | [] -> acc;;
DEMO Generating drawings from lists
Adding new dimension to drawings Expressions that define 3D objects Just like math and 2D graphics Fun.colorColor.DarkRedFun.cone $ ( Fun.colorColor.Goldenrod     (Fun.translate (0.0, 0.0, 1.0)  Fun.cylinder) );; val it : Drawing3D = (...) > Fun.cube;; val it : Drawing3D = (...)
DEMO Introducing general recursion using 3D objects
Links and Q & A Functional variations Web Site Cross-platform F# supportTeaching materials for F#, etc… http://functional-variations.net If you’re interested in more, get in touch! http://tomasp.net | tomas@tomasp.net  http://twitter.com/tomaspetricek

More Related Content

What's hot

Pipeline oriented programming
Pipeline oriented programmingPipeline oriented programming
Pipeline oriented programmingScott Wlaschin
 
仕事で使うF#
仕事で使うF#仕事で使うF#
仕事で使うF#bleis tift
 
Chapter 1 Basic Programming (Python Programming Lecture)
Chapter 1 Basic Programming (Python Programming Lecture)Chapter 1 Basic Programming (Python Programming Lecture)
Chapter 1 Basic Programming (Python Programming Lecture)IoT Code Lab
 
F# Presentation
F# PresentationF# Presentation
F# Presentationmrkurt
 
46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1AmIt Prasad
 
Chapter 2 Decision Making (Python Programming Lecture)
Chapter 2 Decision Making (Python Programming Lecture)Chapter 2 Decision Making (Python Programming Lecture)
Chapter 2 Decision Making (Python Programming Lecture)IoT Code Lab
 
Python unit 2 as per Anna university syllabus
Python unit 2 as per Anna university syllabusPython unit 2 as per Anna university syllabus
Python unit 2 as per Anna university syllabusDhivyaSubramaniyam
 
Game of Life - Polyglot FP - Haskell - Scala - Unison - Part 3
Game of Life - Polyglot FP - Haskell - Scala - Unison - Part 3Game of Life - Polyglot FP - Haskell - Scala - Unison - Part 3
Game of Life - Polyglot FP - Haskell - Scala - Unison - Part 3Philip Schwarz
 
Function recap
Function recapFunction recap
Function recapalish sha
 
03. Operators Expressions and statements
03. Operators Expressions and statements03. Operators Expressions and statements
03. Operators Expressions and statementsIntro C# Book
 
Python programming workshop session 1
Python programming workshop session 1Python programming workshop session 1
Python programming workshop session 1Abdul Haseeb
 
Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...
Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...
Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...Philip Schwarz
 

What's hot (19)

Rx workshop
Rx workshopRx workshop
Rx workshop
 
Pipeline oriented programming
Pipeline oriented programmingPipeline oriented programming
Pipeline oriented programming
 
仕事で使うF#
仕事で使うF#仕事で使うF#
仕事で使うF#
 
Chapter 1 Basic Programming (Python Programming Lecture)
Chapter 1 Basic Programming (Python Programming Lecture)Chapter 1 Basic Programming (Python Programming Lecture)
Chapter 1 Basic Programming (Python Programming Lecture)
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
Intro to c++
Intro to c++Intro to c++
Intro to c++
 
F# Presentation
F# PresentationF# Presentation
F# Presentation
 
46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1
 
Ch8a
Ch8aCh8a
Ch8a
 
Chapter 2 Decision Making (Python Programming Lecture)
Chapter 2 Decision Making (Python Programming Lecture)Chapter 2 Decision Making (Python Programming Lecture)
Chapter 2 Decision Making (Python Programming Lecture)
 
Python unit 2 as per Anna university syllabus
Python unit 2 as per Anna university syllabusPython unit 2 as per Anna university syllabus
Python unit 2 as per Anna university syllabus
 
Game of Life - Polyglot FP - Haskell - Scala - Unison - Part 3
Game of Life - Polyglot FP - Haskell - Scala - Unison - Part 3Game of Life - Polyglot FP - Haskell - Scala - Unison - Part 3
Game of Life - Polyglot FP - Haskell - Scala - Unison - Part 3
 
Function recap
Function recapFunction recap
Function recap
 
Software Construction Assignment Help
Software Construction Assignment HelpSoftware Construction Assignment Help
Software Construction Assignment Help
 
03. Operators Expressions and statements
03. Operators Expressions and statements03. Operators Expressions and statements
03. Operators Expressions and statements
 
Ch8b
Ch8bCh8b
Ch8b
 
Python programming workshop session 1
Python programming workshop session 1Python programming workshop session 1
Python programming workshop session 1
 
Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...
Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...
Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...
 
Computer Science Assignment Help
Computer Science Assignment HelpComputer Science Assignment Help
Computer Science Assignment Help
 

Similar to Teaching F#

Similar to Teaching F# (20)

Functional programming with FSharp
Functional programming with FSharpFunctional programming with FSharp
Functional programming with FSharp
 
Cs6660 compiler design november december 2016 Answer key
Cs6660 compiler design november december 2016 Answer keyCs6660 compiler design november december 2016 Answer key
Cs6660 compiler design november december 2016 Answer key
 
Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Data Analysis with R (combined slides)
Data Analysis with R (combined slides)
 
Introduction to F#
Introduction to F#Introduction to F#
Introduction to F#
 
Functional Programming in Excel
Functional Programming in ExcelFunctional Programming in Excel
Functional Programming in Excel
 
Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative Practice
 
Computer Graphics Concepts
Computer Graphics ConceptsComputer Graphics Concepts
Computer Graphics Concepts
 
Amusing C#
Amusing C#Amusing C#
Amusing C#
 
Lecture 6: linked list
Lecture 6:  linked listLecture 6:  linked list
Lecture 6: linked list
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Computational Assignment Help
Computational Assignment HelpComputational Assignment Help
Computational Assignment Help
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
 
3D Represent.docx
3D Represent.docx3D Represent.docx
3D Represent.docx
 
14 class design (1)
14 class design (1)14 class design (1)
14 class design (1)
 
14 class design
14 class design14 class design
14 class design
 
C
CC
C
 
C++
C++C++
C++
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xii
 

More from Tomas Petricek

Coeffects: A Calculus of Context-Dependent Computation
Coeffects: A Calculus of Context-Dependent ComputationCoeffects: A Calculus of Context-Dependent Computation
Coeffects: A Calculus of Context-Dependent ComputationTomas Petricek
 
Domain Specific Languages: The Functional Way
Domain Specific Languages: The Functional WayDomain Specific Languages: The Functional Way
Domain Specific Languages: The Functional WayTomas Petricek
 
F# Data: Making structured data first class citizens
F# Data: Making structured data first class citizensF# Data: Making structured data first class citizens
F# Data: Making structured data first class citizensTomas Petricek
 
Doing data science with F# (BuildStuff)
Doing data science with F# (BuildStuff)Doing data science with F# (BuildStuff)
Doing data science with F# (BuildStuff)Tomas Petricek
 
Doing data science with F#
Doing data science with F#Doing data science with F#
Doing data science with F#Tomas Petricek
 
F# and Financial Data Making Data Analysis Simple
F# and Financial Data Making Data Analysis SimpleF# and Financial Data Making Data Analysis Simple
F# and Financial Data Making Data Analysis SimpleTomas Petricek
 
Creating Domain Specific Languages in F#
Creating Domain Specific Languages in F#Creating Domain Specific Languages in F#
Creating Domain Specific Languages in F#Tomas Petricek
 
How F# Learned to Stop Worrying and Love the Data
How F# Learned to Stop Worrying and Love the DataHow F# Learned to Stop Worrying and Love the Data
How F# Learned to Stop Worrying and Love the DataTomas Petricek
 
Information-rich programming in F# (ML Workshop 2012)
Information-rich programming in F# (ML Workshop 2012)Information-rich programming in F# (ML Workshop 2012)
Information-rich programming in F# (ML Workshop 2012)Tomas Petricek
 
F# Type Providers in Depth
F# Type Providers in DepthF# Type Providers in Depth
F# Type Providers in DepthTomas Petricek
 
Asynchronous programming in F# (QCon 2012)
Asynchronous programming in F# (QCon 2012)Asynchronous programming in F# (QCon 2012)
Asynchronous programming in F# (QCon 2012)Tomas Petricek
 
Queries in general purpose languages
Queries in general purpose languagesQueries in general purpose languages
Queries in general purpose languagesTomas Petricek
 
Accessing loosely structured data from F# and C#
Accessing loosely structured data from F# and C#Accessing loosely structured data from F# and C#
Accessing loosely structured data from F# and C#Tomas Petricek
 
Concurrent programming with Agents
Concurrent programming with AgentsConcurrent programming with Agents
Concurrent programming with AgentsTomas Petricek
 

More from Tomas Petricek (18)

Coeffects: A Calculus of Context-Dependent Computation
Coeffects: A Calculus of Context-Dependent ComputationCoeffects: A Calculus of Context-Dependent Computation
Coeffects: A Calculus of Context-Dependent Computation
 
Domain Specific Languages: The Functional Way
Domain Specific Languages: The Functional WayDomain Specific Languages: The Functional Way
Domain Specific Languages: The Functional Way
 
F# Data: Making structured data first class citizens
F# Data: Making structured data first class citizensF# Data: Making structured data first class citizens
F# Data: Making structured data first class citizens
 
Doing data science with F# (BuildStuff)
Doing data science with F# (BuildStuff)Doing data science with F# (BuildStuff)
Doing data science with F# (BuildStuff)
 
Doing data science with F#
Doing data science with F#Doing data science with F#
Doing data science with F#
 
F# and Financial Data Making Data Analysis Simple
F# and Financial Data Making Data Analysis SimpleF# and Financial Data Making Data Analysis Simple
F# and Financial Data Making Data Analysis Simple
 
Creating Domain Specific Languages in F#
Creating Domain Specific Languages in F#Creating Domain Specific Languages in F#
Creating Domain Specific Languages in F#
 
How F# Learned to Stop Worrying and Love the Data
How F# Learned to Stop Worrying and Love the DataHow F# Learned to Stop Worrying and Love the Data
How F# Learned to Stop Worrying and Love the Data
 
Information-rich programming in F# (ML Workshop 2012)
Information-rich programming in F# (ML Workshop 2012)Information-rich programming in F# (ML Workshop 2012)
Information-rich programming in F# (ML Workshop 2012)
 
F# Type Providers in Depth
F# Type Providers in DepthF# Type Providers in Depth
F# Type Providers in Depth
 
Asynchronous programming in F# (QCon 2012)
Asynchronous programming in F# (QCon 2012)Asynchronous programming in F# (QCon 2012)
Asynchronous programming in F# (QCon 2012)
 
Queries in general purpose languages
Queries in general purpose languagesQueries in general purpose languages
Queries in general purpose languages
 
Accessing loosely structured data from F# and C#
Accessing loosely structured data from F# and C#Accessing loosely structured data from F# and C#
Accessing loosely structured data from F# and C#
 
F# on the Server-Side
F# on the Server-SideF# on the Server-Side
F# on the Server-Side
 
F# Tutorial @ QCon
F# Tutorial @ QConF# Tutorial @ QCon
F# Tutorial @ QCon
 
F# in MonoDevelop
F# in MonoDevelopF# in MonoDevelop
F# in MonoDevelop
 
Academia
AcademiaAcademia
Academia
 
Concurrent programming with Agents
Concurrent programming with AgentsConcurrent programming with Agents
Concurrent programming with Agents
 

Recently uploaded

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 

Recently uploaded (20)

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 

Teaching F#

  • 1. Teaching F#From numerical expressions to 3D graphics Tomáš Petříček F# enthusiast and F# book author PhD student at University of Cambridge
  • 2. Target audience Freshman students Basic knowledge of math principles(Not too much – they may not like it) Earlier in high-school or later at university should be fine too Possibly first programming course Controversial topic, but F# has many benefits
  • 3. Related functional textbooks #1 Emphasize theory and abstract thinking
  • 4. Related functional textbooks #2 Functional programming with fun demos
  • 5. Why F# as a first language? Mathematically oriented language Supplements math and theory courses Eliminates differences between students Open-source with cross-platform support F# for MonoDevelop on Linux/Mac Practical language with some market .NET/Mono skills are valued by industry Very easy transition to C# and other languages
  • 6. Expressions in F# First functional programming steps
  • 7. What F# shares with math? Language is exact – we need to precisely say what we want to get Composition does not break things – we can mix various correct facts Things do not change – theorems will always be true, π will not change
  • 8. Pythagorean theorem Math has equations and expressions Expressions can be evaluated Using F# Interactive > sqrt((pown 3.0 2) + (pown 4.0 2));; val it : float = 5.0
  • 9. Introducing let declarations and if Solving quadratic equations Script for solving written in F# let d = pown b 2 - 4.0 * a * c;; if d < 0.0 then "No real solution" elifd > 0.0 then "Two solutions" else "One solution";; let x1 = (-b + sqrt d) / 2.0 * a let x2 = (-b - sqrt d) / 2.0 * a;;
  • 10. DEMO Working with F# expressions
  • 11. Composing graphics in F# Fun examples for students to play with
  • 12. Composing graphics Expressions that have drawing as the result Same concepts as mathematical expressions Basic shapes Functions for creating new shapes > Fun.circle100.0f;; val it : Drawing = (Drawing 100x100) > Fun.fillColorColor.Goldenrod (Fun.circle 100.0f);; val it : Drawing = (Drawing 100x100)
  • 13. Composing drawings using custom operator ($) Let declarations to reuse drawings Fun.circle200.0f $ Fun.move 0.0f 150.0f (Fun.circle 100.0f) let plus = Fun.lineStyle 2.0f Color.SteelBlue ( Fun.line -10.0f 0.0f 10.0f 0.0f $ Fun.line 0.0f -10.0f 0.0f 10.0f ) let star = plus $ (Fun.rotate 45.0f plus) let bigStar = Fun.scale 2.0f 2.0f star Working with shapes
  • 14. DEMO Creating drawings using F# expressions
  • 15. Introducing recursion and 3D Difficult concepts explained using graphics
  • 16. Explaining recursion Recursion is tricky concept Two types of recursions (from HTDP) Structural – follows recursive data structure For example lists, trees, expressions etc. Such functions must terminate in F# General – arbitrary recursive calls May not terminate (if it is not well written) For example generating fractals
  • 17. General recursion for lists Not tail-recursive list length Easy visualization of execution Not tail-recursive – work done on the “way back” let rec length list = match list with | [] -> 0 | head::tail -> (length tail) + 1
  • 18. General recursion for lists Tail-recursive list length All work done on the way “forward” This is what tail-recursive means! let rec length acc list = match list with | head::tail -> let newacc = acc + 1 in length newacc tail | [] -> acc;;
  • 20. Adding new dimension to drawings Expressions that define 3D objects Just like math and 2D graphics Fun.colorColor.DarkRedFun.cone $ ( Fun.colorColor.Goldenrod (Fun.translate (0.0, 0.0, 1.0) Fun.cylinder) );; val it : Drawing3D = (...) > Fun.cube;; val it : Drawing3D = (...)
  • 21. DEMO Introducing general recursion using 3D objects
  • 22. Links and Q & A Functional variations Web Site Cross-platform F# supportTeaching materials for F#, etc… http://functional-variations.net If you’re interested in more, get in touch! http://tomasp.net | tomas@tomasp.net http://twitter.com/tomaspetricek