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

More Related Content

DOC
Framework Project Portfolio
DOCX
Cambio de bases
PDF
APPlause - DemoCamp Munich
PPTX
SPFx working with SharePoint data
PPTX
SPFx: Working with SharePoint Content
TXT
New text document
PPTX
Actions & Filters In WordPress
PDF
Higher Order Components and Render Props
Framework Project Portfolio
Cambio de bases
APPlause - DemoCamp Munich
SPFx working with SharePoint data
SPFx: Working with SharePoint Content
New text document
Actions & Filters In WordPress
Higher Order Components and Render Props

What's hot (20)

PDF
知っておきたいSpring Batch Tips
PDF
Hidden Docs in Angular
DOCX
VPN Access Runbook
PPT
e computer notes - Producing readable output with i sql plus
PDF
Deep Dive into React Hooks
DOCX
Week 12 code
PPTX
Durable functions
PPT
Best core & advanced java classes in mumbai
PDF
Dependency Injection with CDI in 15 minutes
PDF
SQLite in Adobe AIR
PPTX
PHP Traits
PPT
Ajax
PPTX
Typescript barcelona
PDF
안드로이드 세미나 2
PPTX
Introduction to CDI and DI in Java EE 6
PPTX
PPT
Php Reusing Code And Writing Functions
KEY
안드로이드 세미나 2
PDF
DBD::SQLite
知っておきたいSpring Batch Tips
Hidden Docs in Angular
VPN Access Runbook
e computer notes - Producing readable output with i sql plus
Deep Dive into React Hooks
Week 12 code
Durable functions
Best core & advanced java classes in mumbai
Dependency Injection with CDI in 15 minutes
SQLite in Adobe AIR
PHP Traits
Ajax
Typescript barcelona
안드로이드 세미나 2
Introduction to CDI and DI in Java EE 6
Php Reusing Code And Writing Functions
안드로이드 세미나 2
DBD::SQLite
Ad

Viewers also liked (13)

PDF
Module Cv (Juli 2010)
PDF
My sql in_enterprise
PPTX
F# Tutorial @ QCon
PDF
Marc Dujardin Introduction of a user-orientated design paradigm
PPT
Object-Oriented Concepts
PPTX
encapsulation
PPTX
Encapsulation
PPTX
Applications of extrusion in encapsulation technology
PPTX
Encapsulation
PDF
Javascript foundations: Introducing OO
PDF
Paradigm Wars: Object Oriented Vs Functional Programming in creating MarkParser
PPT
20. Object-Oriented Programming Fundamental Principles
PPT
Object Oriented Programming with Java
Module Cv (Juli 2010)
My sql in_enterprise
F# Tutorial @ QCon
Marc Dujardin Introduction of a user-orientated design paradigm
Object-Oriented Concepts
encapsulation
Encapsulation
Applications of extrusion in encapsulation technology
Encapsulation
Javascript foundations: Introducing OO
Paradigm Wars: Object Oriented Vs Functional Programming in creating MarkParser
20. Object-Oriented Programming Fundamental Principles
Object Oriented Programming with Java
Ad

Similar to F# in the enterprise (20)

PDF
C# quick ref (bruce 2016)
DOC
Framework Project
PPTX
Generic Programming &amp; Collection
PPTX
Generic Programming &amp; Collection
PPTX
COLLECTIONS.pptx
PPT
Generics collections
PPT
Advanced c#
PPTX
2. overview of c#
PPTX
CSharp for Unity - Day 1
PPT
Generics Collections
PPTX
Collections and generics
PPTX
.Net Framework 2 fundamentals
PPS
Net framework session02
PPTX
Collections and its types in C# (with examples)
PPTX
C# 6 and 7 and Futures 20180607
PPTX
Lowering in C#: What really happens with your code?, from NDC Oslo 2019
PPTX
PDC Video on C# 4.0 Futures
PDF
LectureNotes-06-DSA
PPT
C Language fundamentals hhhhhhhhhhhh.ppt
C# quick ref (bruce 2016)
Framework Project
Generic Programming &amp; Collection
Generic Programming &amp; Collection
COLLECTIONS.pptx
Generics collections
Advanced c#
2. overview of c#
CSharp for Unity - Day 1
Generics Collections
Collections and generics
.Net Framework 2 fundamentals
Net framework session02
Collections and its types in C# (with examples)
C# 6 and 7 and Futures 20180607
Lowering in C#: What really happens with your code?, from NDC Oslo 2019
PDC Video on C# 4.0 Futures
LectureNotes-06-DSA
C Language fundamentals hhhhhhhhhhhh.ppt

Recently uploaded (20)

PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
Hybrid model detection and classification of lung cancer
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
A review of recent deep learning applications in wood surface defect identifi...
PDF
August Patch Tuesday
PDF
A comparative study of natural language inference in Swahili using monolingua...
PPTX
observCloud-Native Containerability and monitoring.pptx
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
Developing a website for English-speaking practice to English as a foreign la...
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
DOCX
search engine optimization ppt fir known well about this
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Zenith AI: Advanced Artificial Intelligence
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PPTX
Web Crawler for Trend Tracking Gen Z Insights.pptx
PPTX
Modernising the Digital Integration Hub
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
Five Habits of High-Impact Board Members
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Hybrid model detection and classification of lung cancer
DP Operators-handbook-extract for the Mautical Institute
A review of recent deep learning applications in wood surface defect identifi...
August Patch Tuesday
A comparative study of natural language inference in Swahili using monolingua...
observCloud-Native Containerability and monitoring.pptx
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
Developing a website for English-speaking practice to English as a foreign la...
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
search engine optimization ppt fir known well about this
Univ-Connecticut-ChatGPT-Presentaion.pdf
A contest of sentiment analysis: k-nearest neighbor versus neural network
Group 1 Presentation -Planning and Decision Making .pptx
Zenith AI: Advanced Artificial Intelligence
Final SEM Unit 1 for mit wpu at pune .pptx
Web Crawler for Trend Tracking Gen Z Insights.pptx
Modernising the Digital Integration Hub
NewMind AI Weekly Chronicles – August ’25 Week III
Five Habits of High-Impact Board Members

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

Editor's Notes

  • #7: 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