SlideShare a Scribd company logo
1 of 34
Tomas Petricek ,[object Object],[object Object],Accessing loosely structured data from F# and C# http://tomasp.net/blog  | @tomaspetricek
A little bit about me… ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The Problem
The Problem ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
What you’ll learn today ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Dynamic in C# and F# ,[object Object],[object Object],[object Object],[object Object],X ml Element   element   =   GetElement (); int   size  =  e lement . Attribute < int > ( &quot;Size&quot; );
Dynamic in C# and F# ,[object Object],[object Object],dynamic   element   =   GetElement (); int   size  =  e lement . Size ; let   element   =   GetElement (); let  size  =  e lement ? Size ;
Demo:  Using  WorldBank data in C#
Dynamic type in C# ,[object Object],[object Object],class   DynamicWorldBank  :  DynamicObject   { public   override   bool   TryInvokeMember ( InvokeMemberBinder   binder ,  object []  args ,  out   object   result)   { result   =   /* member access for 'binder.Name' */ return   true ; } } dynamic   wb   =   new   DynamicWorldBank (); dynamic   regions   =   wb . Region ( new  {  PerPage   =   100  });
Simple database access in F# ,[object Object],[object Object],[object Object],let   getCategories()  :   seq < int   *  string >   =   [   for   row   in   db . Query ? GetProducts ()  ->  row ? ID ,  row ? Name   ] let  ( ? ) ( x : Row)  ( name : string )  :   ' R   =   x . Reader . [ name ]  :?>   ' R
Demo:  Calling database in F#
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Structure in the language ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Domain modeling in LINQ ,[object Object],[object Object],[object Object],public   partial   class   Books   { [ Column ( Storage = &quot;_ID&quot; ,  DbType = &quot;Int&quot; ,  IsPrimaryKey = true )] public   int   ID  {  get ;  set ; } [ Column ( Storage = &quot;_Title&quot; ,  DbType = &quot;VarChar(100)&quot; )] public   string   Title  {  get ;  set ; } } var   q   =   from   p   in   db . GetTable < Books > () select   p . Title ;
Domain modeling in F# ,[object Object],[object Object],[object Object],Primitive values ,[object Object],Records ,[object Object],Discriminated unions
Demo:  Nicer database access
Nicer database access in F# ,[object Object],[object Object],[object Object],let   load ()  :   seq < Book >   =   let   db   =   new   DynamicDatabase ( connectionString ) db . Query ? Get Books ()  type   Book   =   {  ID   :   int ;  Title   :   string  }
Domain modeling in F#
Domain modeling in F# ,[object Object],type   Title   =   Title   of   string type   Link   =   Link   of   string type   Description   =   Description   of   string /// Item consists of title, link and description type   Item   =   Item   of   Title   *   Link   *   Description /// Represents channel with title (etc.) and list of items type   Channel   =   Channel   of   Title   *   Link   *   Description   *   list < Item > /// Represents RSS feed containing a channel type   Rss   =   Rss   of   Channel
Working with XML ,[object Object],[object Object],[object Object],[object Object],[object Object],let   rss  =   StructuralXml . Load ( &quot;http://.../feed&quot; ) match   rss . Root   with |  Rss ( Channel ( Title   title ,  _ , _,  items ))  ->   printfn   &quot;%s (%d items)&quot;   title   items . Length
Demo:  Working with XML
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The Problem ,[object Object]
The Solution ,[object Object]
Demo:  Accessing WorldBank data
What is a type provider? ,[object Object],[object Object],[object Object],[object Object],public   interface   ITypeProvider   { Type []  GetTypes (); Expression   GetInvokerExpression (   MethodBase   method ,  ParameterExpression []  params  ); event   EventHandler   Invalidate ; }
Type provider trickery ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Demo:  Accessing Freebase data
Summary ,[object Object],Dynamic type or operator ,[object Object],[object Object],[object Object],Domain model ,[object Object],[object Object],[object Object],Type providers ,[object Object],[object Object],[object Object]
Discussion ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
BONUS
World Bank provider details ,[object Object],[object Object],[object Object],type   Runtime   = static   member   GetValuesByCountryAndIndicator ( country : string ,  indicator : string )  :   seq < int   *   float >   =   seq  {  for  ( k ,  v )  in   WorldBank . GetData  [ country ;  indicator ]  do if   not  ( String . IsNullOrEmpty   v )  then   yield   int   k ,  float   v  } static   member   GetCountriesByRegion ( code : string )  :   seq < string >   = seq  {  for  ( key , _)  in   WorldBank . GetCountries ( code )  ->   key  }
Calling PHP from C# ,[object Object],[object Object],class   SampleObj  { function   Add ($ a , $ b ) {  return  $ a   +  $ b ; } } [ DuckType ] public   interface   ISampleObj  { int   Add ( int   i1 ,  int   i2 ); } ISampleObj   so   =   ctx . New < ISampleObj > ( &quot;SampleObj&quot; ); int   res   =   so . Add ( 18 ,  26 );

More Related Content

What's hot

F# and functional programming
F# and functional programmingF# and functional programming
F# and functional programmingramikarjalainen
 
History of F#, and the ML family of languages.
History of F#, and the ML family of languages. History of F#, and the ML family of languages.
History of F#, and the ML family of languages. Rachel Reese
 
F# Eye for the C# Guy
F# Eye for the C# GuyF# Eye for the C# Guy
F# Eye for the C# Guygueste3f83d
 
Mercury: A Functional Review
Mercury: A Functional ReviewMercury: A Functional Review
Mercury: A Functional ReviewMark Cheeseman
 
Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented TechnologiesUmesh Nikam
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++Ankur Pandey
 
Microsoft Silverlight
Microsoft SilverlightMicrosoft Silverlight
Microsoft Silverlightguest3a8196
 
c# usage,applications and advantages
c# usage,applications and advantages c# usage,applications and advantages
c# usage,applications and advantages mohamed drahem
 
Object Oriented Programming With Real-World Scenario
Object Oriented Programming With Real-World ScenarioObject Oriented Programming With Real-World Scenario
Object Oriented Programming With Real-World ScenarioDurgesh Singh
 
C++ OOP Implementation
C++ OOP ImplementationC++ OOP Implementation
C++ OOP ImplementationFridz Felisco
 
Functional Programming in C# and F#
Functional Programming in C# and F#Functional Programming in C# and F#
Functional Programming in C# and F#Alfonso Garcia-Caro
 
Meta Languages Railroad Diagrams Student Version
Meta Languages Railroad Diagrams Student VersionMeta Languages Railroad Diagrams Student Version
Meta Languages Railroad Diagrams Student VersionKelly Bauer
 
Language processor implementation using python
Language processor implementation using pythonLanguage processor implementation using python
Language processor implementation using pythonViktor Pyskunov
 
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...cprogrammings
 

What's hot (20)

F# and functional programming
F# and functional programmingF# and functional programming
F# and functional programming
 
History of F#, and the ML family of languages.
History of F#, and the ML family of languages. History of F#, and the ML family of languages.
History of F#, and the ML family of languages.
 
F# Eye for the C# Guy
F# Eye for the C# GuyF# Eye for the C# Guy
F# Eye for the C# Guy
 
Mercury: A Functional Review
Mercury: A Functional ReviewMercury: A Functional Review
Mercury: A Functional Review
 
basics of c++
basics of c++basics of c++
basics of c++
 
Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented Technologies
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++
 
Microsoft Silverlight
Microsoft SilverlightMicrosoft Silverlight
Microsoft Silverlight
 
1 puc programming using c++
1 puc programming using c++1 puc programming using c++
1 puc programming using c++
 
c# usage,applications and advantages
c# usage,applications and advantages c# usage,applications and advantages
c# usage,applications and advantages
 
Object Oriented Programming With Real-World Scenario
Object Oriented Programming With Real-World ScenarioObject Oriented Programming With Real-World Scenario
Object Oriented Programming With Real-World Scenario
 
C++ OOP Implementation
C++ OOP ImplementationC++ OOP Implementation
C++ OOP Implementation
 
Functional Programming in C# and F#
Functional Programming in C# and F#Functional Programming in C# and F#
Functional Programming in C# and F#
 
Meta Languages Railroad Diagrams Student Version
Meta Languages Railroad Diagrams Student VersionMeta Languages Railroad Diagrams Student Version
Meta Languages Railroad Diagrams Student Version
 
Protocol buffers
Protocol buffersProtocol buffers
Protocol buffers
 
Ppt of c++ vs c#
Ppt of c++ vs c#Ppt of c++ vs c#
Ppt of c++ vs c#
 
Language processor implementation using python
Language processor implementation using pythonLanguage processor implementation using python
Language processor implementation using python
 
Introduction to c++ ppt 1
Introduction to c++ ppt 1Introduction to c++ ppt 1
Introduction to c++ ppt 1
 
C presentation
C presentationC presentation
C presentation
 
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
 

Similar to Accessing loosely structured data from F# and C#

Visual Studio .NET2010
Visual Studio .NET2010Visual Studio .NET2010
Visual Studio .NET2010Satish Verma
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesEelco Visser
 
Smoothing Your Java with DSLs
Smoothing Your Java with DSLsSmoothing Your Java with DSLs
Smoothing Your Java with DSLsintelliyole
 
Exploring SharePoint with F#
Exploring SharePoint with F#Exploring SharePoint with F#
Exploring SharePoint with F#Talbott Crowell
 
Drupaljam xl 2019 presentation multilingualism makes better programmers
Drupaljam xl 2019 presentation   multilingualism makes better programmersDrupaljam xl 2019 presentation   multilingualism makes better programmers
Drupaljam xl 2019 presentation multilingualism makes better programmersAlexander Varwijk
 
PDC Video on C# 4.0 Futures
PDC Video on C# 4.0 FuturesPDC Video on C# 4.0 Futures
PDC Video on C# 4.0 Futuresnithinmohantk
 
.NET and C# introduction
.NET and C# introduction.NET and C# introduction
.NET and C# introductionPeter Gfader
 
Visual studio 2008
Visual studio 2008Visual studio 2008
Visual studio 2008Luis Enrique
 
F# for functional enthusiasts
F# for functional enthusiastsF# for functional enthusiasts
F# for functional enthusiastsJack Fox
 
Intake 38 data access 5
Intake 38 data access 5Intake 38 data access 5
Intake 38 data access 5Mahmoud Ouf
 
Visual Studio 2010 and .NET 4.0 Overview
Visual Studio 2010 and .NET 4.0 OverviewVisual Studio 2010 and .NET 4.0 Overview
Visual Studio 2010 and .NET 4.0 Overviewbwullems
 
PERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptx
PERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptxPERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptx
PERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptxTriSandhikaJaya
 
Linguistic Abstraction for the Web
Linguistic Abstraction for the WebLinguistic Abstraction for the Web
Linguistic Abstraction for the WebEelco Visser
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial EnAnkur Dongre
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial EnAnkur Dongre
 
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)Igor Moochnick
 

Similar to Accessing loosely structured data from F# and C# (20)

Visual Studio .NET2010
Visual Studio .NET2010Visual Studio .NET2010
Visual Studio .NET2010
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific Languages
 
Smoothing Your Java with DSLs
Smoothing Your Java with DSLsSmoothing Your Java with DSLs
Smoothing Your Java with DSLs
 
Intake 37 ef2
Intake 37 ef2Intake 37 ef2
Intake 37 ef2
 
Exploring SharePoint with F#
Exploring SharePoint with F#Exploring SharePoint with F#
Exploring SharePoint with F#
 
Drupaljam xl 2019 presentation multilingualism makes better programmers
Drupaljam xl 2019 presentation   multilingualism makes better programmersDrupaljam xl 2019 presentation   multilingualism makes better programmers
Drupaljam xl 2019 presentation multilingualism makes better programmers
 
PDC Video on C# 4.0 Futures
PDC Video on C# 4.0 FuturesPDC Video on C# 4.0 Futures
PDC Video on C# 4.0 Futures
 
.NET and C# introduction
.NET and C# introduction.NET and C# introduction
.NET and C# introduction
 
Visual studio 2008
Visual studio 2008Visual studio 2008
Visual studio 2008
 
F# for functional enthusiasts
F# for functional enthusiastsF# for functional enthusiasts
F# for functional enthusiasts
 
Intake 38 data access 5
Intake 38 data access 5Intake 38 data access 5
Intake 38 data access 5
 
Visual Studio 2010 and .NET 4.0 Overview
Visual Studio 2010 and .NET 4.0 OverviewVisual Studio 2010 and .NET 4.0 Overview
Visual Studio 2010 and .NET 4.0 Overview
 
1204csharp
1204csharp1204csharp
1204csharp
 
PERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptx
PERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptxPERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptx
PERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptx
 
WPF and Databases
WPF and DatabasesWPF and Databases
WPF and Databases
 
Linguistic Abstraction for the Web
Linguistic Abstraction for the WebLinguistic Abstraction for the Web
Linguistic Abstraction for the Web
 
Linq
LinqLinq
Linq
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
 
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
 

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
 
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
 
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
 
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
 
Docase notation for Haskell
Docase notation for HaskellDocase notation for Haskell
Docase notation for HaskellTomas Petricek
 
Concurrent programming with Agents
Concurrent programming with AgentsConcurrent programming with Agents
Concurrent programming with AgentsTomas Petricek
 

More from Tomas Petricek (15)

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
 
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#
 
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)
 
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
 
Docase notation for Haskell
Docase notation for HaskellDocase notation for Haskell
Docase notation for Haskell
 
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
 
Teaching F#
Teaching F#Teaching F#
Teaching F#
 
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
 

Accessing loosely structured data from F# and C#