SlideShare uma empresa Scribd logo
1 de 11
DaveThomas
 First class .Net Language citizen
 Multi paradigm language
 Functional
 Object orientated
 Well suited for:
 Financial
 Statistical
 Testing
 Event processing
 Tool development
 General purpose components
 General server-side development
 Referential transparency / deterministic
 Immutability
 First class functions
 Higher order functions
 Recursion
 Reasoning
 Code behaves in a consistent understandable manner
 Safety
 Contents of variables are always as expected no unknown
mutation
 Reduction code
 Code can be safely reused
 Data Sharing
 Threading is easier and locks are no longer needed
 Testing
 Concise functions that are easy to test
 Code reduction
 Typically around 70%
 Increased performance
 Easy to parallelise functions
 Increased productivity
 Common to experience 50% boost
 Increasing importance of multi-core and cloud
 F# facilitates building multi-core friendly code
 Reduced maintenance costs
 Bugs and compiler issues are found earlier, typically during REPL
(Read-Eval-Print Loop is for interactive compilation and exploration)
 Easy to create Domain specific languages
 Financial services
 Credit Suisse –Valuation, Quant models
 Insurance rating
 Grange insurance – Insurance Rating Engine
 Energy trading
 Eon EnergyTrading – pluggable calculation engines
 Statistical analysis
 Xbox live (TrueSkill)
 C# already had functional features
 LINQ, Lambda expressions, predicates, closures
 Uses the same .Net libraries
 Can be consumed by other .Net languages
 Start with core components
 Algorithm development
 Data analysis
 parallel batch processing
 rapid prototyping
 Testing
Object pool -C#
Example taken from
the MSDN website
2Types
20 Lines in base class
41 lines in derived class
using System.Collections.Generic;
using System.Diagnostics;
namespace System.Collections.Concurrent
{
/// <summary>Provides a thread-safe object pool.</summary>
/// <typeparam name="T">Specifies the type of the elements stored in the pool.</typeparam>
[DebuggerDisplay("Count={Count}")]
[DebuggerTypeProxy(typeof(IProducerConsumerCollection_DebugView<>))]
public sealed class ObjectPool<T> : ProducerConsumerCollectionBase<T>
{
private readonlyFunc<T> _generator;
/// <summary>Initializes an instance of the ObjectPool class.</summary>
/// <param name="generator">The function used to create items when no items exist in the
pool.</param>
public ObjectPool(Func<T> generator) : this(generator, new ConcurrentQueue<T>()) { }
/// <summary>Initializes an instance of the ObjectPool class.</summary>
/// <param name="generator">The function used to create items when no items exist in the
pool.</param>
/// <param name="collection">The collection used to store the elements of the pool.</param>
public ObjectPool(Func<T> generator, IProducerConsumerCollection<T> collection)
: base(collection)
{
if (generator == null) throw new ArgumentNullException("generator");
_generator = generator;
}
/// <summary>Adds the provided item into the pool.</summary>
/// <param name="item">The item to be added.</param>
public void PutObject(T item) { base.TryAdd(item); }
/// <summary>Gets an item from the pool.</summary>
/// <returns>The removed or created item.</returns>
/// <remarks>If the pool is empty, a new item will be created and returned.</remarks>
public T GetObject()
{
T value;
return base.TryTake(out value) ? value : _generator();
}
/// <summary>Clears the object pool, returning all of the data that was in the pool.</summary>
/// <returns>An array containing all of the elements in the pool.</returns>
public T[] ToArrayAndClear()
{
var items = new List<T>();
T value;
while (base.TryTake(out value)) items.Add(value);
return items.ToArray();
}
protected override boolTryAdd(T item)
{
PutObject(item);
return true;
}
protected override boolTryTake(out T item)
{
item = GetObject();
return true;
}
}
}
/// <summary>
/// Provides a base implementation for producer-consumer collections that wrap other
/// producer-consumer collections.
/// </summary>
/// <typeparam name="T">Specifies the type of elements in the collection.</typeparam>
[Serializable]
public abstract class ProducerConsumerCollectionBase<T> : IProducerConsumerCollection<T>
{
private readonlyIProducerConsumerCollection<T> _contained;
/// <summary>Initializes the ProducerConsumerCollectionBase instance.</summary>
/// <param name="contained">The collection to be wrapped by this instance.</param>
protected ProducerConsumerCollectionBase(IProducerConsumerCollection<T> contained)
{
if (contained == null) throw new ArgumentNullException("contained");
_contained = contained;
}
/// <summary>Gets the contained collection.</summary>
protected IProducerConsumerCollection<T>ContainedCollection { get { return _contained; } }
/// <summary>Attempts to add the specified value to the end of the deque.</summary>
/// <param name="item">The item to add.</param>
/// <returns>true if the item could be added; otherwise, false.</returns>
protected virtual boolTryAdd(T item) { return _contained.TryAdd(item); }
/// <summary>Attempts to remove and return an item from the collection.</summary>
/// <param name="item">
/// When this method returns, if the operation was successful, item contains the item removed. If
/// no item was available to be removed, the value is unspecified.
/// </param>
/// <returns>
/// true if an element was removed and returned from the collection; otherwise, false.
/// </returns>
protected virtual boolTryTake(out T item) { return _contained.TryTake(out item); }
/// <summary>Attempts to add the specified value to the end of the deque.</summary>
/// <param name="item">The item to add.</param>
/// <returns>true if the item could be added; otherwise, false.</returns>
boolIProducerConsumerCollection<T>.TryAdd(T item) { return TryAdd(item); }
/// <summary>Attempts to remove and return an item from the collection.</summary>
/// <param name="item">
/// When this method returns, if the operation was successful, item contains the item removed. If
/// no item was available to be removed, the value is unspecified.
/// </param>
/// <returns>
/// true if an element was removed and returned from the collection; otherwise, false.
/// </returns>
boolIProducerConsumerCollection<T>.TryTake(out T item) { return TryTake(out item); }
/// <summary>Gets the number of elements contained in the collection.</summary>
public int Count { get { return _contained.Count; } }
/// <summary>Creates an array containing the contents of the collection.</summary>
/// <returns>The array.</returns>
public T[] ToArray() { return _contained.ToArray(); }
/// <summary>Copies the contents of the collection to an array.</summary>
/// <param name="array">The array to which the data should be copied.</param>
/// <param name="index">The starting index at which data should be copied.</param>
public void CopyTo(T[] array, int index) { _contained.CopyTo(array, index); }
/// <summary>Copies the contents of the collection to an array.</summary>
/// <param name="array">The array to which the data should be copied.</param>
/// <param name="index">The starting index at which data should be copied.</param>
void ICollection.CopyTo(Array array, int index) { _contained.CopyTo(array, index); }
/// <summary>Gets an enumerator for the collection.</summary>
/// <returns>An enumerator.</returns>
public IEnumerator<T>GetEnumerator() { return _contained.GetEnumerator(); }
/// <summary>Gets an enumerator for the collection.</summary>
/// <returns>An enumerator.</returns>
IEnumeratorIEnumerable.GetEnumerator() { return GetEnumerator(); }
/// <summary>Gets whether the collection is synchronized.</summary>
boolICollection.IsSynchronized { get { return _contained.IsSynchronized; } }
/// <summary>Gets the synchronization root object for the collection.</summary>
object ICollection.SyncRoot { get { return _contained.SyncRoot; } }
Agent based object pool
25 Lines of code
1Type alias
2Types
F#
25 Lines 689 Characters
59% less Lines
66% less Characters
C#
61 Lines 2041 Characters
2.4x more Lines
2.96x more Characters
functions
modulePoc
//Agent alias for MailboxProcessor
typeAgent<'T>=MailboxProcessor<'T>
///One of three messages for our Object Pool agent
typePoolMessage<'a>=
| GetofAsyncReplyChannel<'a>
| Putof'a
| ClearofAsyncReplyChannel<List<'a>>
/// Object pool representing a reusable pool of objects
typeObjectPool<'a>(generate:unit->'a, initialPoolCount) =
letinitial=List.initinitialPoolCount (fun (x) ->generate())
letagent=Agent.Start(funinbox->
letrecloop(x) =async {
let!msg=inbox.Receive()
matchmsgwith
| Get(reply) ->
letres=matchxwith
| a::b->reply.Reply(a);b
| [] asempty->reply.Reply(generate());empty
return!loop(res)
| Put(value)->return!loop(value::x)
| Clear(reply) ->
reply.Reply(x)
return!loop(List.empty<'a>) }
loop(initial))
/// Clears the object pool, returning all of the data that was in the pool.
memberthis.ToListAndClear() =agent.PostAndAsyncReply(Clear)
/// Puts an item into the pool
memberthis.Put(item ) =agent.Post(item)
/// Gets an item from the pool or if there are none present use the generator
memberthis.Get(item) =agent.PostAndAsyncReply(Get)
 F# open source project - FractureIO
 High performance networking
 Composable pipeline library
 Agent based infrastructure
F# in the enterprise

Mais conteúdo relacionado

Mais procurados

VPN Access Runbook
VPN Access RunbookVPN Access Runbook
VPN Access Runbook
Taha Shakeel
 
e computer notes - Producing readable output with i sql plus
e computer notes - Producing readable output with i sql pluse computer notes - Producing readable output with i sql plus
e computer notes - Producing readable output with i sql plus
ecomputernotes
 
SQLite in Adobe AIR
SQLite in Adobe AIRSQLite in Adobe AIR
SQLite in Adobe AIR
Peter Elst
 
Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6
Ray Ploski
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
mussawir20
 

Mais procurados (20)

Stored procedure
Stored procedureStored procedure
Stored procedure
 
知っておきたいSpring Batch Tips
知っておきたいSpring Batch Tips知っておきたいSpring Batch Tips
知っておきたいSpring Batch Tips
 
Hidden Docs in Angular
Hidden Docs in AngularHidden Docs in Angular
Hidden Docs in Angular
 
VPN Access Runbook
VPN Access RunbookVPN Access Runbook
VPN Access Runbook
 
e computer notes - Producing readable output with i sql plus
e computer notes - Producing readable output with i sql pluse computer notes - Producing readable output with i sql plus
e computer notes - Producing readable output with i sql plus
 
Deep Dive into React Hooks
Deep Dive into React HooksDeep Dive into React Hooks
Deep Dive into React Hooks
 
Week 12 code
Week 12 codeWeek 12 code
Week 12 code
 
Durable functions
Durable functionsDurable functions
Durable functions
 
Best core & advanced java classes in mumbai
Best core & advanced java classes in mumbaiBest core & advanced java classes in mumbai
Best core & advanced java classes in mumbai
 
Dependency Injection with CDI in 15 minutes
Dependency Injection with CDI in 15 minutesDependency Injection with CDI in 15 minutes
Dependency Injection with CDI in 15 minutes
 
SQLite in Adobe AIR
SQLite in Adobe AIRSQLite in Adobe AIR
SQLite in Adobe AIR
 
PHP Traits
PHP TraitsPHP Traits
PHP Traits
 
Ajax
AjaxAjax
Ajax
 
Typescript barcelona
Typescript barcelonaTypescript barcelona
Typescript barcelona
 
안드로이드 세미나 2
안드로이드 세미나 2안드로이드 세미나 2
안드로이드 세미나 2
 
Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6
 
Vue next
Vue nextVue next
Vue next
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
 
안드로이드 세미나 2
안드로이드 세미나 2안드로이드 세미나 2
안드로이드 세미나 2
 
DBD::SQLite
DBD::SQLiteDBD::SQLite
DBD::SQLite
 

Destaque

Module Cv (Juli 2010)
Module Cv (Juli 2010)Module Cv (Juli 2010)
Module Cv (Juli 2010)
abvandepol
 
Object-Oriented Concepts
Object-Oriented ConceptsObject-Oriented Concepts
Object-Oriented Concepts
Abdalla Mahmoud
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
Jussi Pohjolainen
 

Destaque (13)

Module Cv (Juli 2010)
Module Cv (Juli 2010)Module Cv (Juli 2010)
Module Cv (Juli 2010)
 
My sql in_enterprise
My sql in_enterpriseMy sql in_enterprise
My sql in_enterprise
 
F# Tutorial @ QCon
F# Tutorial @ QConF# Tutorial @ QCon
F# Tutorial @ QCon
 
Marc Dujardin Introduction of a user-orientated design paradigm
Marc Dujardin Introduction of a user-orientated design paradigmMarc Dujardin Introduction of a user-orientated design paradigm
Marc Dujardin Introduction of a user-orientated design paradigm
 
Object-Oriented Concepts
Object-Oriented ConceptsObject-Oriented Concepts
Object-Oriented Concepts
 
encapsulation
encapsulationencapsulation
encapsulation
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 
Applications of extrusion in encapsulation technology
Applications of extrusion in encapsulation technologyApplications of extrusion in encapsulation technology
Applications of extrusion in encapsulation technology
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 
Javascript foundations: Introducing OO
Javascript foundations: Introducing OOJavascript foundations: Introducing OO
Javascript foundations: Introducing OO
 
Paradigm Wars: Object Oriented Vs Functional Programming in creating MarkParser
Paradigm Wars: Object Oriented Vs Functional Programming in creating MarkParserParadigm Wars: Object Oriented Vs Functional Programming in creating MarkParser
Paradigm Wars: Object Oriented Vs Functional Programming in creating MarkParser
 
20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 

Semelhante a F# in the enterprise

Sitecore 7: A developers quest to mastering unit testing
Sitecore 7: A developers quest to mastering unit testingSitecore 7: A developers quest to mastering unit testing
Sitecore 7: A developers quest to mastering unit testing
nonlinear creations
 
First java-server-faces-tutorial-en
First java-server-faces-tutorial-enFirst java-server-faces-tutorial-en
First java-server-faces-tutorial-en
techbed
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
habib_786
 

Semelhante a F# in the enterprise (20)

Framework Project
Framework  ProjectFramework  Project
Framework Project
 
Sitecore 7: A developers quest to mastering unit testing
Sitecore 7: A developers quest to mastering unit testingSitecore 7: A developers quest to mastering unit testing
Sitecore 7: A developers quest to mastering unit testing
 
Flink Batch Processing and Iterations
Flink Batch Processing and IterationsFlink Batch Processing and Iterations
Flink Batch Processing and Iterations
 
The state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon DublinThe state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon Dublin
 
Thymeleaf and Spring Controllers.ppt
Thymeleaf and Spring Controllers.pptThymeleaf and Spring Controllers.ppt
Thymeleaf and Spring Controllers.ppt
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
 
WPF and Prism 4.1 Workshop at BASTA Austria
WPF and Prism 4.1 Workshop at BASTA AustriaWPF and Prism 4.1 Workshop at BASTA Austria
WPF and Prism 4.1 Workshop at BASTA Austria
 
Getting the Most Out of jQuery Widgets
Getting the Most Out of jQuery WidgetsGetting the Most Out of jQuery Widgets
Getting the Most Out of jQuery Widgets
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 
How to Bring Common UI Patterns to ADF
How to Bring Common UI Patterns to ADF How to Bring Common UI Patterns to ADF
How to Bring Common UI Patterns to ADF
 
Fewd week6 slides
Fewd week6 slidesFewd week6 slides
Fewd week6 slides
 
Practica n° 7
Practica n° 7Practica n° 7
Practica n° 7
 
Introduction to Spring MVC
Introduction to Spring MVCIntroduction to Spring MVC
Introduction to Spring MVC
 
First java-server-faces-tutorial-en
First java-server-faces-tutorial-enFirst java-server-faces-tutorial-en
First java-server-faces-tutorial-en
 
Angular JS2 Training Session #2
Angular JS2 Training Session #2Angular JS2 Training Session #2
Angular JS2 Training Session #2
 
How te bring common UI patterns to ADF
How te bring common UI patterns to ADFHow te bring common UI patterns to ADF
How te bring common UI patterns to ADF
 
Codeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept ImplementationCodeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept Implementation
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
 
Struts2 - 101
Struts2 - 101Struts2 - 101
Struts2 - 101
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 

F# in the enterprise

  • 2.  First class .Net Language citizen  Multi paradigm language  Functional  Object orientated  Well suited for:  Financial  Statistical  Testing  Event processing  Tool development  General purpose components  General server-side development
  • 3.  Referential transparency / deterministic  Immutability  First class functions  Higher order functions  Recursion
  • 4.  Reasoning  Code behaves in a consistent understandable manner  Safety  Contents of variables are always as expected no unknown mutation  Reduction code  Code can be safely reused  Data Sharing  Threading is easier and locks are no longer needed  Testing  Concise functions that are easy to test
  • 5.  Code reduction  Typically around 70%  Increased performance  Easy to parallelise functions  Increased productivity  Common to experience 50% boost  Increasing importance of multi-core and cloud  F# facilitates building multi-core friendly code  Reduced maintenance costs  Bugs and compiler issues are found earlier, typically during REPL (Read-Eval-Print Loop is for interactive compilation and exploration)  Easy to create Domain specific languages
  • 6.  Financial services  Credit Suisse –Valuation, Quant models  Insurance rating  Grange insurance – Insurance Rating Engine  Energy trading  Eon EnergyTrading – pluggable calculation engines  Statistical analysis  Xbox live (TrueSkill)
  • 7.  C# already had functional features  LINQ, Lambda expressions, predicates, closures  Uses the same .Net libraries  Can be consumed by other .Net languages  Start with core components  Algorithm development  Data analysis  parallel batch processing  rapid prototyping  Testing
  • 8. Object pool -C# Example taken from the MSDN website 2Types 20 Lines in base class 41 lines in derived class using System.Collections.Generic; using System.Diagnostics; namespace System.Collections.Concurrent { /// <summary>Provides a thread-safe object pool.</summary> /// <typeparam name="T">Specifies the type of the elements stored in the pool.</typeparam> [DebuggerDisplay("Count={Count}")] [DebuggerTypeProxy(typeof(IProducerConsumerCollection_DebugView<>))] public sealed class ObjectPool<T> : ProducerConsumerCollectionBase<T> { private readonlyFunc<T> _generator; /// <summary>Initializes an instance of the ObjectPool class.</summary> /// <param name="generator">The function used to create items when no items exist in the pool.</param> public ObjectPool(Func<T> generator) : this(generator, new ConcurrentQueue<T>()) { } /// <summary>Initializes an instance of the ObjectPool class.</summary> /// <param name="generator">The function used to create items when no items exist in the pool.</param> /// <param name="collection">The collection used to store the elements of the pool.</param> public ObjectPool(Func<T> generator, IProducerConsumerCollection<T> collection) : base(collection) { if (generator == null) throw new ArgumentNullException("generator"); _generator = generator; } /// <summary>Adds the provided item into the pool.</summary> /// <param name="item">The item to be added.</param> public void PutObject(T item) { base.TryAdd(item); } /// <summary>Gets an item from the pool.</summary> /// <returns>The removed or created item.</returns> /// <remarks>If the pool is empty, a new item will be created and returned.</remarks> public T GetObject() { T value; return base.TryTake(out value) ? value : _generator(); } /// <summary>Clears the object pool, returning all of the data that was in the pool.</summary> /// <returns>An array containing all of the elements in the pool.</returns> public T[] ToArrayAndClear() { var items = new List<T>(); T value; while (base.TryTake(out value)) items.Add(value); return items.ToArray(); } protected override boolTryAdd(T item) { PutObject(item); return true; } protected override boolTryTake(out T item) { item = GetObject(); return true; } } } /// <summary> /// Provides a base implementation for producer-consumer collections that wrap other /// producer-consumer collections. /// </summary> /// <typeparam name="T">Specifies the type of elements in the collection.</typeparam> [Serializable] public abstract class ProducerConsumerCollectionBase<T> : IProducerConsumerCollection<T> { private readonlyIProducerConsumerCollection<T> _contained; /// <summary>Initializes the ProducerConsumerCollectionBase instance.</summary> /// <param name="contained">The collection to be wrapped by this instance.</param> protected ProducerConsumerCollectionBase(IProducerConsumerCollection<T> contained) { if (contained == null) throw new ArgumentNullException("contained"); _contained = contained; } /// <summary>Gets the contained collection.</summary> protected IProducerConsumerCollection<T>ContainedCollection { get { return _contained; } } /// <summary>Attempts to add the specified value to the end of the deque.</summary> /// <param name="item">The item to add.</param> /// <returns>true if the item could be added; otherwise, false.</returns> protected virtual boolTryAdd(T item) { return _contained.TryAdd(item); } /// <summary>Attempts to remove and return an item from the collection.</summary> /// <param name="item"> /// When this method returns, if the operation was successful, item contains the item removed. If /// no item was available to be removed, the value is unspecified. /// </param> /// <returns> /// true if an element was removed and returned from the collection; otherwise, false. /// </returns> protected virtual boolTryTake(out T item) { return _contained.TryTake(out item); } /// <summary>Attempts to add the specified value to the end of the deque.</summary> /// <param name="item">The item to add.</param> /// <returns>true if the item could be added; otherwise, false.</returns> boolIProducerConsumerCollection<T>.TryAdd(T item) { return TryAdd(item); } /// <summary>Attempts to remove and return an item from the collection.</summary> /// <param name="item"> /// When this method returns, if the operation was successful, item contains the item removed. If /// no item was available to be removed, the value is unspecified. /// </param> /// <returns> /// true if an element was removed and returned from the collection; otherwise, false. /// </returns> boolIProducerConsumerCollection<T>.TryTake(out T item) { return TryTake(out item); } /// <summary>Gets the number of elements contained in the collection.</summary> public int Count { get { return _contained.Count; } } /// <summary>Creates an array containing the contents of the collection.</summary> /// <returns>The array.</returns> public T[] ToArray() { return _contained.ToArray(); } /// <summary>Copies the contents of the collection to an array.</summary> /// <param name="array">The array to which the data should be copied.</param> /// <param name="index">The starting index at which data should be copied.</param> public void CopyTo(T[] array, int index) { _contained.CopyTo(array, index); } /// <summary>Copies the contents of the collection to an array.</summary> /// <param name="array">The array to which the data should be copied.</param> /// <param name="index">The starting index at which data should be copied.</param> void ICollection.CopyTo(Array array, int index) { _contained.CopyTo(array, index); } /// <summary>Gets an enumerator for the collection.</summary> /// <returns>An enumerator.</returns> public IEnumerator<T>GetEnumerator() { return _contained.GetEnumerator(); } /// <summary>Gets an enumerator for the collection.</summary> /// <returns>An enumerator.</returns> IEnumeratorIEnumerable.GetEnumerator() { return GetEnumerator(); } /// <summary>Gets whether the collection is synchronized.</summary> boolICollection.IsSynchronized { get { return _contained.IsSynchronized; } } /// <summary>Gets the synchronization root object for the collection.</summary> object ICollection.SyncRoot { get { return _contained.SyncRoot; } }
  • 9. Agent based object pool 25 Lines of code 1Type alias 2Types F# 25 Lines 689 Characters 59% less Lines 66% less Characters C# 61 Lines 2041 Characters 2.4x more Lines 2.96x more Characters functions modulePoc //Agent alias for MailboxProcessor typeAgent<'T>=MailboxProcessor<'T> ///One of three messages for our Object Pool agent typePoolMessage<'a>= | GetofAsyncReplyChannel<'a> | Putof'a | ClearofAsyncReplyChannel<List<'a>> /// Object pool representing a reusable pool of objects typeObjectPool<'a>(generate:unit->'a, initialPoolCount) = letinitial=List.initinitialPoolCount (fun (x) ->generate()) letagent=Agent.Start(funinbox-> letrecloop(x) =async { let!msg=inbox.Receive() matchmsgwith | Get(reply) -> letres=matchxwith | a::b->reply.Reply(a);b | [] asempty->reply.Reply(generate());empty return!loop(res) | Put(value)->return!loop(value::x) | Clear(reply) -> reply.Reply(x) return!loop(List.empty<'a>) } loop(initial)) /// Clears the object pool, returning all of the data that was in the pool. memberthis.ToListAndClear() =agent.PostAndAsyncReply(Clear) /// Puts an item into the pool memberthis.Put(item ) =agent.Post(item) /// Gets an item from the pool or if there are none present use the generator memberthis.Get(item) =agent.PostAndAsyncReply(Get)
  • 10.  F# open source project - FractureIO  High performance networking  Composable pipeline library  Agent based infrastructure

Notas do Editor

  1. Credit Suisse – rapid development or modelsGrange Insurance - order of magnitude speed increase, running what if scenarios, parrellismEon Energy Trading – pluggable calculation enginesXbox live – Multi-Terrabyte parsing and analytics