Introduction to F# Scalable, Type-safe, Succinct, Interoperable, Mathematically-oriented Programming for.NET Don Syme MSR Cambridge

Slides:



Advertisements
Similar presentations
Svetlin Nakov Director Training and Consulting Activities National Academy for Software Development (NASD) ASP.NET 3.5 New Features.
Advertisements

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 15 Introduction to Rails.
Extending Eclipse CDT for Remote Target Debugging Thomas Fletcher Director, Automotive Engineering Services QNX Software Systems.
.NET Technology. Introduction Overview of.NET What.NET means for Developers, Users and Businesses Two.NET Research Projects:.NET Generics AsmL.
TouchDevelop: Productive Scripting on and for Mobile Devices and Web Services Thomas Ball Sebastian Burckhardt, Peli de Halleux, Michał Moskal, Nikolai.
.NET Framework Overview
Tahir Nawaz Introduction to.NET Framework. .NET – What Is It? Software platform Language neutral In other words:.NET is not a language (Runtime and a.
Using.NET Platform Note: Most of the material of these slides have been adapted from Nakov’s excellent overview for.NET framework, MSDN and Wikipedia Muhammad.
Database System Concepts and Architecture
Chapter 1 Introduction to Visual Basic Programming and Applications 1 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta.
Designing, Deploying and Managing Workflow in SharePoint Sites Steve Heaney Product Development Manager OBS
Page 1 GADD Software - An Introduction Public version, August 2014, gaddsoftware.com.
... a programming language. ...a functional programming language.
Introduction to.NET Technology Marcello Benati Software Engineer.NET Architect.
OS Case Study: The Xbox 360  Instructor: Rob Nash  Readings: See citations in the slides.
August 29, 2002InforMax Confidential1 Vector PathBlazer Product Overview.
J2EE Java 2 Enterprise Edition. Relevant Topics in The Java Tutorial Topic Web Page JDBC orial/jdbc
F# Shiva Srivastava David He Peter Bingel. Overview F# (pronounced "F sharp") is a functional and object oriented programming language for the Microsoft.NET.
Chapter 10 Application Development. Chapter Goals Describe the application development process and the role of methodologies, models and tools Compare.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Copyright Arshi Khan1 System Programming Instructor Arshi Khan.
Microsoft Visual Basic 2012 CHAPTER ONE Introduction to Visual Basic 2012 Programming.
Microsoft Visual Basic 2005 CHAPTER 1 Introduction to Visual Basic 2005 Programming.
GPPC Connections 2011 | November 6-8 | Las Vegas, NV Dynamics GP12 Web Client Today and in the Future Kevin Racer, Sr. Program Manager.
Introduction COMP104: Fundamentals and Methodology.
SharePoint 2010 Business Intelligence Module 10: Reporting Services.
CS 0004 –Lecture 1 Wednesday, Jan 5 th, 2011 Roxana Gheorghiu.
Basics of Web Databases With the advent of Web database technology, Web pages are no longer static, but dynamic with connection to a back-end database.
Session 1 - Introduction and Data Access Layer
11 Getting Started with C# Chapter Objectives You will be able to: 1. Say in general terms how C# differs from C. 2. Create, compile, and run a.
Microsoft Application Virtualization 5.0: Introduction Mohnish Chaturvedi & Ian Bartlett Premier Field Engineer WCL312.
DBSQL 14-1 Copyright © Genetic Computer School 2009 Chapter 14 Microsoft SQL Server.
NOTE: To change the image on this slide, select the picture and delete it. Then click the Pictures icon in the placeholder to insert your own image. WEB.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
Contents 1.Introduction, architecture 2.Live demonstration 3.Extensibility.
Ch 1. A Python Q&A Session Spring Why do people use Python? Software quality Developer productivity Program portability Support libraries Component.
Selected Topics in Software Engineering - Distributed Software Development.
1 Geospatial and Business Intelligence Jean-Sébastien Turcotte Executive VP San Francisco - April 2007 Streamlining web mapping applications.
1 EECS 6083 Compiler Theory Based on slides from text web site: Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Tim Madden ODG/XSD.  Graphics Processing Unit  Graphics card on your PC.  “Hardware accelerated graphics”  Video game industry is main driver.  More.
ASP.NET (Active Server Page) SNU OOPSLA Lab. October 2005.
Application Software System Software.
Chapter 1 Basic Concepts of Operating Systems Introduction Software A program is a sequence of instructions that enables the computer to carry.
Text Introduction to.NET Framework. CONFIDENTIAL Agenda .NET Training – Purpose  What is.NET?  Why.NET?  Advantages  Architecture  Components: CLR,
Microsoft Visual Basic 2015 CHAPTER ONE Introduction to Visual Basic 2015 Programming.
Your Interactive Guide to the Digital World Discovering Computers 2012 Chapter 13 Computer Programs and Programming Languages.
Hadoop Javad Azimi May What is Hadoop? Software platform that lets one easily write and run applications that process vast amounts of data. It includes:
MILESTONES IN SOFTWARE
Computer System Structures
Introduction to Visual Basic. NET,. NET Framework and Visual Studio
Introducing the Microsoft® .NET Framework
Kai Li, Allen D. Malony, Sameer Shende, Robert Bell
Windows Programming Environments
Top 8 Best Programming Languages To Learn
DotNetSpider Editor Hefin Dsouza
Chapter 9: The Client/Server Database Environment
.NET Framework 2.0 .NET Framework 3.0 .NET Framework 3.5
Introduction to Visual Basic 2008 Programming
Spark Presentation.
The Transition to Modern Office Add-in Development
Introduction to .NET Framework Ch2 – Deitel’s Book
The Client/Server Database Environment
CE-105 Spring 2007 Engr. Faisal ur Rehman
Programming COMP104: Fundamentals and Methodology Introduction.
.NET and .NET Core Foot View of .NET Pan Wuming 2017.
CIS16 Application Development – Programming with Visual Basic
Introduction to .NET By : Mr. V. D. Panchal Content :
F# 3.0: data, services, Web, cloud, at your fingertips
Introduction of Week 11 Return assignment 9-1 Collect assignment 10-1
Mark Quirk Head of Technology Developer & Platform Group
Presentation transcript:

Introduction to F# Scalable, Type-safe, Succinct, Interoperable, Mathematically-oriented Programming for.NET Don Syme MSR Cambridge

Today… F# overview Some introductory F# programming Two case studies

Which functional language: Connects with all Microsoft and most Open Source foundation technologies? Has 100s of Microsoft and open source developers working on its runtime systems, JIT compilers and libraries? Has concurrent GC and SMP support? Has CPU profilers, memory profilers, debuggers, test, doc tools? Lets you publish types and code accessible by 100,000s of developers? Consists of only ~25K LOC

F# = ML in the world of.NET Debuggers, Profilers etc. VisualStudio, SharpDevelop GUI Libraries, DirectX etc. System.I/O System.Net etc. Sockets etc. C#.NET Common Language Runtime Visual Basic Database Libraries F# Languages are central, but must interoperate; A language is judged on its connectivity;

Introducing F#... A.NET language Aims to combine much of Lisp, ML, Scheme and Haskell in the context of.NET Functional, math-oriented, scalable Aimed particularly at the "Symbolic Scripting and Programming" niche at Microsoft e.g. Static Driver Verifier, Terminator, Machine Learning, Vision and more

F# as a Language Core ML Modules-as- values, functors OCaml F# OCaml-Objects and other extensions Core ML.NET API Access Other extensions + tools Common core language

Some Simple F# let data = (1,2,3) let sqr x = x * x let f (x,y,z) = (sqr x, sqr y, sqr z) let sx,sy,sz = f (10,20,30) printf "hello world"; 1+2 let show (x,y,z) = Console.WriteLine("hello world"); let sx,sy,sz = f (x,y,z) in printf Results = %d,%d,%d (sx,sy,sz); sqrs let (|>) x f = f x parentheses optional on application sequencing local binding, sequencing NOTE: type inferred val data: int * int * int val sqr: int -> int pipelining operator pattern matching let pastaProducts = productList |> Set.filter (fun x -> x.Contains("Ravioli")) |> Set.union tortelliniProducts |> Set.to_array

Some Sample F# Programming

Video...

Orthogonal & Unified Constructs Functions: unified and simple (fun x -> x + 1) let f x y = x * y let g x y = x + y let p = (f,g) predicate = 'a -> bool send = 'a -> unit threadStart = unit -> unit comparer = 'a -> 'a -> int hasher = 'a -> int equality = 'a -> 'a -> bool 100s of "delegate" types in.NET platform effectively unified away

Effective abstractions Type parameters Discriminated unions Pattern matching Type inference Recursion (Mutually-referential objects) Map List Set type expr = | Sum of expr * expr | Prod of expr * expr …. match expr with | Sum(a,b) ->... | Prod(a,b) ->... …. let rec map =...

Typical F# Project Architecture Base Tools Windows (any edition).NET Framework 2.0 F# Readily Accessible Extras Visual Studio 2005 SQL Server 2005 Alchemi (.NET distribution framework) also many, many others e.g. Visual C++, DirectX, dnAnalytics, MKL, LAPACK, MATLAB, AJAX libraries etc. etc. etc. C++ simulation engine private C# matrix library Web Database SQL Server Database Data Access Simulation Interactive Visualization Scripting.NET Framework libraries F# MATLAB File-based Databases Analysis etc. etc. etc.

Case Study: TrueSkill Live game ranking algorithms in F#

TrueSkill Skill based ranking for Xbox Live! from MSR. Skill is a normal distribution Mean is the expected skill Variance is the uncertainty

F# as a Scripting Language Problem: Parsing 110 GB of Xbox matchmaking log data (12 days). Data spreads over 11,000 text files in over 300 directories. Task: Importing data in structural form into a SQL database. Code: 90 lines long! Development time (code): 1 – 2 hours. Performance: In under 18 hours = 10,000 log lines processed per second!

F# for Large Scale Data Analysis Problem: Analysis of 4.2 million Xbox user feedbacks (4 months worth of data). Data is already in a SQL database. Task: Adopt TrueSkill model to the user feedback problem for integration into the Xbox service. Code: 100 lines long! Development time (code): 3 – 4 hours. Performance: 10 minutes runtime for the whole dataset!

F# for Complex Scientific Modelling Problem: Framework for probabilistic inference (research). Task: Extensible and thin factor graph library. Code: 400 lines long (comparable C# code: 2000 lines) Development time (code): 2 weeks. Performance: Excellent Why F#? Deep.Net Integration. System.IO System.IO System.Data.SqlClient System.Data.SqlClient Custom TrueSkill C# libraries. Custom TrueSkill C# libraries. Custom C# Matrix library. Custom C# Matrix library. Interactive development. Full Visual Studio integration. Built-in type inference. Anonymous functions. Pattern matching.

What they say… New F# user (experienced OO programmer) "We crunched 400Gb of data, scripting over smaller sets then finally running 3 days with 15 computers. The UI code streams a 100Mb CSV file from disk in around 5 seconds, while simultaneously calculating and drawing a histogram." The F# code has excellent performance. F# is fun! I really enjoyed the brevity of the resulting code. It helped me focus on the ends, not the means. The F# code was easy to maintain and evolve

Performance and related issues

Benchmark Performance by Language MS Confidential

F# and OCAML benchmarks MS Confidential

Running times for benchmarks MS Confidential

Calling C/C++ C SAT Solver Accessed from F# Type-safe F# wrapper

#2: Calling F# from C# LogWeave (Office XAF Optimization Tool) 4000 lines C#, using Abstract IL library Using types defined in F# il.mli/ilbind.mli type Method type MethodDef val bmeth_hash : Method -> int val bmeth_eq : Method -> Method -> bool val bmeth_compare : Method -> Method -> int val mk_bmeth : Type * MethodDef * Types -> Method val mk_generalized_bmeth : Type * MethodDef -> Method val generalize_bmeth : Method -> Method Using functions defined in F#

#3: Paint.NET & Plugins Plugin written in F# Here is the DLL

F# and LINQ

Language Integrated Queries with F#/LINQ db.Customers |> where « fun c -> c.City = "London" » |> select « fun c -> c.ContactName » ["Thomas Hardy"; "Victoria Ashworth"; "Elizabeth Brown"; "Ann Devon"; "Simon Crowther"; "Hari Kumar"] SELECT [t0].[ContactName] FROM [Customers] AS [t0] = [t0].[City]

The Vision: Heterogeneous Execution Today languages use homogeneous execution: The CPU The natural extension of the LINQ vision is heterogeneous execution, leveraging The database The server The GPU The web browser (ala AJAX) Symbolic execution Write your code in one language, execute it in many completely different ways

Accelerate ahead with F# Quotations! let nextGeneration(a) = let sum = rot a (-1) (-1).+ rot a (-1) 0.+ rot a (-1) 1.+ rot a 0 (-1).+ rot a rot a 1 (-1).+ rot a rot a 1 1 in (sum.= three).|| ((sum.= two).&& a);; GPU assembly code Graphics Card Accelerator.dll nextGeneration aaccelerate a CPU Metaprogram Program

Case Study: SPiM Interactive Chemical/Biological Stochastic Simulation with F#

#3: SPiM: Biological Simulation and Visualization

Summary

Challenges of modern language design Statically typed, hence Scalable (> 100K LOC) Interactive Interoperable Safe Libraries Good Platform Efficient Succinct Its the combination that counts

Summary.NET F# 1.1 An excellent combination for practical scientific programming.NET gives you a rich software eco-system of relevant, polished components F# gives you scripting, performance and the beauty and productivity of functional programming Enjoy!

Questions?