SlideShare a Scribd company logo
F# CODE QUOTATIONS:
CODE-AS-DATA
JACK PAPPAS, DMITRY MOROZOV
SEPTEMBER 19, 2013
SOURCES
•http://tinyurl.com/fs-code-
quotations
RECAP
• First appeared in Lisp: '(one two three) vs (one two three). Hence the
name.
• Code as Data (meta-programming, Language Oriented Programming)
• Transformation (to the same or other language)
• Explicit construction and evaluation
• Numerous usage examples:
• F# query expressions , LINQ
• Foq/Moq/Unquote - testing frameworks
• Type providers development
• F# to GPU (Jack's work)
• WebSharper, FunScript, M-Brace, etc.
F# QUOTATIONS VS C# EXPRESSION
TREES
• C# doesn't require caller to have explicit quotation
• F# quotations literals support full language (almost) as opposed to C#
expr. trees
• F# ReflectedDefinitionAttribute - ability to quote programming
language entities: methods, classes, modules
• Composition: F# splicing vs C# OOP
• Decomposition: F# active patterns vs Visitor pattern
QUOTATIONS CONSTRUCTION
• Quotation literals
• Example: <@ 1 + 2 @>
• Explicit construction using Quotations.Expr type factory methods
• Example:
• let op_Add = Type.GetType("Microsoft.FSharp.Core.Operators,
FSharp.Core").GetMethod("op_Addition").MakeGenericMethod(typeof<int>,
typeof<int>, typeof<int>)
• Expr.Cast<int>(Expr.Call(op_Add, [Expr.Value 1; Expr.Value 2]))
• Splicing
• let x = <@ 1 @> in <@ %x + 2 @>
TYPE PROVIDERS IMPLEMENTATION
• Quotations is an essential tool for Type Providers development
TYPE PROVIDER 101
1. Create project using “F# Type Provider Template” by Tao Liu
2. Change “Debug” settings “Start” section to open same solution
within another instance of IDE
3. Replace ProvidedTypes-head.* with the latest from
http://fsharp3sample.codeplex.com/
4. Congratulations! You have skeleton of a working type provider
5. Now pick a data source, develop an new Type Provider and become
F# ninja
SQL COMMAND TYPE PROVIDER
• Dapper on sterioids
• Use SQL Data Tools to develop functional data access layer
• FUNCTIONS, VIEWS, TABLES
• CROSS APPLY operator (monadic Bind, C# SelectMany)
GUI INPUT VALIDATION
• INotifyDataErrorInfo - WPF 4.5, SL, WinRT
• IDataErrorInfo - WPF 4.0 or less, WinForms (partially)
• Statically-typed
• Would be verbose without F# language features:
• Active patterns
• Explicit member constraints
• Partial application
DATA BINDING
• Making implicit dependency explicit (no magic strings)
• Leveraging F#/.NET type system
• Leveraging IDE/compiler
type IView<'Events, 'Model> =
inherit IObservable<'Events>
abstract SetBindings : 'Model -> unit
<@ textBox.Text <- model.Name @>
textBox.SetBinding(TextBox.TextProperty, "Name")
DATA BINDING MICRO DSL
• Scrap your boilerplate
• F# provides great tools to build internal DSLs
DERIVED PROPERTIES
• Scrap your boilerplate
• F# pure magic
• ReflectedDefinitionAttribute
• Quotation
• Active patterns (a lot)
• WPF black magic (MultiBinding)
• C# way of doing things
• http://knockoutcs.com/index.html
• IL rewriting (PostSharp) or weaving (http://github.com/Fody/PropertyChanged)
WPF WITH F#?
• F# MVC for WPF
• GitHub project:
http://github.com/dmitry-a-morozov/fsharp-wpf-mvc-series
• Wiki:
http://github.com/dmitry-a-morozov/fsharp-wpf-mvc-series/wiki
• F# great general purpose language
• Go thru the framework code base – it’s great language tutorial
• Hard things easy impossible things possible

More Related Content

What's hot (19)

PPTX
Introduction to F# 3.0
Talbott Crowell
 
PPTX
C# language
Akanksha Shukla
 
PPTX
History of F#, and the ML family of languages.
Rachel Reese
 
PPT
Trends in Programming Technology you might want to keep an eye on af Bent Tho...
InfinIT - Innovationsnetværket for it
 
PDF
C# 9 and 10 - What's cool?
Christian Nagel
 
PDF
Swift vs. Language X
Scott Wlaschin
 
PPTX
c# usage,applications and advantages
mohamed drahem
 
PPTX
Procedure oriented programming
MrShahbazRafiq
 
KEY
Remix Your Language Tooling (JSConf.eu 2012)
lennartkats
 
PDF
Create Your Own Language
Hamidreza Soleimani
 
PPT
F# and the DLR
Richard Minerich
 
PDF
LIL Presentation
badsectoracula
 
PPTX
.NET Fest 2019. Алексей Голуб. Монадные парсер-комбинаторы в C# (простой спос...
NETFest
 
KEY
Using Aspects for Language Portability (SCAM 2010)
lennartkats
 
PDF
The Spoofax Language Workbench (SPLASH 2010)
lennartkats
 
PPTX
C programming language
Maha lakshmi
 
PPTX
C languaGE UNIT-1
Malikireddy Bramhananda Reddy
 
PPTX
C & C++ Training in Ambala ! BATRA COMPUTER CENTRE
jatin batra
 
PPTX
C vs c++
Gaurav Badhan
 
Introduction to F# 3.0
Talbott Crowell
 
C# language
Akanksha Shukla
 
History of F#, and the ML family of languages.
Rachel Reese
 
Trends in Programming Technology you might want to keep an eye on af Bent Tho...
InfinIT - Innovationsnetværket for it
 
C# 9 and 10 - What's cool?
Christian Nagel
 
Swift vs. Language X
Scott Wlaschin
 
c# usage,applications and advantages
mohamed drahem
 
Procedure oriented programming
MrShahbazRafiq
 
Remix Your Language Tooling (JSConf.eu 2012)
lennartkats
 
Create Your Own Language
Hamidreza Soleimani
 
F# and the DLR
Richard Minerich
 
LIL Presentation
badsectoracula
 
.NET Fest 2019. Алексей Голуб. Монадные парсер-комбинаторы в C# (простой спос...
NETFest
 
Using Aspects for Language Portability (SCAM 2010)
lennartkats
 
The Spoofax Language Workbench (SPLASH 2010)
lennartkats
 
C programming language
Maha lakshmi
 
C & C++ Training in Ambala ! BATRA COMPUTER CENTRE
jatin batra
 
C vs c++
Gaurav Badhan
 

Similar to Dmitry mozorov on code quotations code as-data for f# (20)

PPTX
Introduction to f#
mjyeaney
 
PDF
"Introduction to F#" - South Dakota Code Camp, November 5, 2011
Blend Interactive
 
PPTX
Introduction to F#
Jonas Follesø
 
PPTX
F# for functional enthusiasts
Jack Fox
 
PPTX
Sharper tools with F#
Kevin Avignon
 
PPTX
Break Free with Managed Functional Programming: An Introduction to F#
Dave Fancher
 
PPTX
Break Free with Managed Functional Programming: An Introduction to F#
IndyMobileNetDev
 
PDF
Madrid F# Meetup: Introduction to F#
Alfonso Garcia-Caro
 
PPT
Accessing loosely structured data from F# and C#
Tomas Petricek
 
PDF
F# for Scala developers
Alfonso Garcia-Caro
 
PPTX
Loving data with F#
Valdis Iljuconoks
 
PPTX
Valdis Iljuconoks - Loving data with F#
DevConFu
 
PDF
Functional Design Patterns (DevTernity 2018)
Scott Wlaschin
 
PDF
Domain Driven Design with the F# type System -- NDC London 2013
Scott Wlaschin
 
PDF
Domain Driven Design with the F# type System -- F#unctional Londoners 2014
Scott Wlaschin
 
PPTX
F# for startups
joelgrus
 
PPTX
F# for startups v2
joelgrus
 
PPTX
TechDaysNL 2015 - DDD with F#
Ronald Harmsen
 
PPTX
Can F# make us better as .NET developers?
Kevin Avignon
 
PPTX
Information-rich programming in F# (ML Workshop 2012)
Tomas Petricek
 
Introduction to f#
mjyeaney
 
"Introduction to F#" - South Dakota Code Camp, November 5, 2011
Blend Interactive
 
Introduction to F#
Jonas Follesø
 
F# for functional enthusiasts
Jack Fox
 
Sharper tools with F#
Kevin Avignon
 
Break Free with Managed Functional Programming: An Introduction to F#
Dave Fancher
 
Break Free with Managed Functional Programming: An Introduction to F#
IndyMobileNetDev
 
Madrid F# Meetup: Introduction to F#
Alfonso Garcia-Caro
 
Accessing loosely structured data from F# and C#
Tomas Petricek
 
F# for Scala developers
Alfonso Garcia-Caro
 
Loving data with F#
Valdis Iljuconoks
 
Valdis Iljuconoks - Loving data with F#
DevConFu
 
Functional Design Patterns (DevTernity 2018)
Scott Wlaschin
 
Domain Driven Design with the F# type System -- NDC London 2013
Scott Wlaschin
 
Domain Driven Design with the F# type System -- F#unctional Londoners 2014
Scott Wlaschin
 
F# for startups
joelgrus
 
F# for startups v2
joelgrus
 
TechDaysNL 2015 - DDD with F#
Ronald Harmsen
 
Can F# make us better as .NET developers?
Kevin Avignon
 
Information-rich programming in F# (ML Workshop 2012)
Tomas Petricek
 
Ad

More from Skills Matter (20)

PDF
5 things cucumber is bad at by Richard Lawrence
Skills Matter
 
ODP
Patterns for slick database applications
Skills Matter
 
PDF
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
Skills Matter
 
ODP
Oscar reiken jr on our success at manheim
Skills Matter
 
PDF
Cukeup nyc ian dees on elixir, erlang, and cucumberl
Skills Matter
 
PDF
Cukeup nyc peter bell on getting started with cucumber.js
Skills Matter
 
PDF
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...
Skills Matter
 
ODP
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...
Skills Matter
 
ODP
Progressive f# tutorials nyc don syme on keynote f# in the open source world
Skills Matter
 
PDF
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...
Skills Matter
 
PDF
A poet's guide_to_acceptance_testing
Skills Matter
 
PDF
Russ miles-cloudfoundry-deep-dive
Skills Matter
 
KEY
Serendipity-neo4j
Skills Matter
 
PDF
Simon Peyton Jones: Managing parallelism
Skills Matter
 
PDF
Plug 20110217
Skills Matter
 
PDF
Lug presentation
Skills Matter
 
PPT
I went to_a_communications_workshop_and_they_t
Skills Matter
 
PDF
Plug saiku
Skills Matter
 
PDF
Huguk lily
Skills Matter
 
PDF
Bootstrapping a-devops-matter
Skills Matter
 
5 things cucumber is bad at by Richard Lawrence
Skills Matter
 
Patterns for slick database applications
Skills Matter
 
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
Skills Matter
 
Oscar reiken jr on our success at manheim
Skills Matter
 
Cukeup nyc ian dees on elixir, erlang, and cucumberl
Skills Matter
 
Cukeup nyc peter bell on getting started with cucumber.js
Skills Matter
 
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...
Skills Matter
 
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...
Skills Matter
 
Progressive f# tutorials nyc don syme on keynote f# in the open source world
Skills Matter
 
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...
Skills Matter
 
A poet's guide_to_acceptance_testing
Skills Matter
 
Russ miles-cloudfoundry-deep-dive
Skills Matter
 
Serendipity-neo4j
Skills Matter
 
Simon Peyton Jones: Managing parallelism
Skills Matter
 
Plug 20110217
Skills Matter
 
Lug presentation
Skills Matter
 
I went to_a_communications_workshop_and_they_t
Skills Matter
 
Plug saiku
Skills Matter
 
Huguk lily
Skills Matter
 
Bootstrapping a-devops-matter
Skills Matter
 
Ad

Recently uploaded (20)

PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Digital Circuits, important subject in CS
contactparinay1
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 

Dmitry mozorov on code quotations code as-data for f#

  • 1. F# CODE QUOTATIONS: CODE-AS-DATA JACK PAPPAS, DMITRY MOROZOV SEPTEMBER 19, 2013
  • 3. RECAP • First appeared in Lisp: '(one two three) vs (one two three). Hence the name. • Code as Data (meta-programming, Language Oriented Programming) • Transformation (to the same or other language) • Explicit construction and evaluation • Numerous usage examples: • F# query expressions , LINQ • Foq/Moq/Unquote - testing frameworks • Type providers development • F# to GPU (Jack's work) • WebSharper, FunScript, M-Brace, etc.
  • 4. F# QUOTATIONS VS C# EXPRESSION TREES • C# doesn't require caller to have explicit quotation • F# quotations literals support full language (almost) as opposed to C# expr. trees • F# ReflectedDefinitionAttribute - ability to quote programming language entities: methods, classes, modules • Composition: F# splicing vs C# OOP • Decomposition: F# active patterns vs Visitor pattern
  • 5. QUOTATIONS CONSTRUCTION • Quotation literals • Example: <@ 1 + 2 @> • Explicit construction using Quotations.Expr type factory methods • Example: • let op_Add = Type.GetType("Microsoft.FSharp.Core.Operators, FSharp.Core").GetMethod("op_Addition").MakeGenericMethod(typeof<int>, typeof<int>, typeof<int>) • Expr.Cast<int>(Expr.Call(op_Add, [Expr.Value 1; Expr.Value 2])) • Splicing • let x = <@ 1 @> in <@ %x + 2 @>
  • 6. TYPE PROVIDERS IMPLEMENTATION • Quotations is an essential tool for Type Providers development
  • 7. TYPE PROVIDER 101 1. Create project using “F# Type Provider Template” by Tao Liu 2. Change “Debug” settings “Start” section to open same solution within another instance of IDE 3. Replace ProvidedTypes-head.* with the latest from http://fsharp3sample.codeplex.com/ 4. Congratulations! You have skeleton of a working type provider 5. Now pick a data source, develop an new Type Provider and become F# ninja
  • 8. SQL COMMAND TYPE PROVIDER • Dapper on sterioids • Use SQL Data Tools to develop functional data access layer • FUNCTIONS, VIEWS, TABLES • CROSS APPLY operator (monadic Bind, C# SelectMany)
  • 9. GUI INPUT VALIDATION • INotifyDataErrorInfo - WPF 4.5, SL, WinRT • IDataErrorInfo - WPF 4.0 or less, WinForms (partially) • Statically-typed • Would be verbose without F# language features: • Active patterns • Explicit member constraints • Partial application
  • 10. DATA BINDING • Making implicit dependency explicit (no magic strings) • Leveraging F#/.NET type system • Leveraging IDE/compiler type IView<'Events, 'Model> = inherit IObservable<'Events> abstract SetBindings : 'Model -> unit <@ textBox.Text <- model.Name @> textBox.SetBinding(TextBox.TextProperty, "Name")
  • 11. DATA BINDING MICRO DSL • Scrap your boilerplate • F# provides great tools to build internal DSLs
  • 12. DERIVED PROPERTIES • Scrap your boilerplate • F# pure magic • ReflectedDefinitionAttribute • Quotation • Active patterns (a lot) • WPF black magic (MultiBinding) • C# way of doing things • http://knockoutcs.com/index.html • IL rewriting (PostSharp) or weaving (http://github.com/Fody/PropertyChanged)
  • 13. WPF WITH F#? • F# MVC for WPF • GitHub project: http://github.com/dmitry-a-morozov/fsharp-wpf-mvc-series • Wiki: http://github.com/dmitry-a-morozov/fsharp-wpf-mvc-series/wiki • F# great general purpose language • Go thru the framework code base – it’s great language tutorial • Hard things easy impossible things possible