This document summarizes an F# talk about information rich programming using F# type providers. The talk introduces F#, demonstrates how type providers allow programming against web-scale data sources with strong typing and IntelliSense, and shows a demo integrating multiple data sources. It concludes by discussing how F# is well-suited for cloud programming and how the language may develop computation expressions for cloud services.
10. Side Effects
• Example: “The Butterfly Effect”
• A side effect
• Modifies some state
• Has observable interaction with calling functions
• Has observable interaction with the outside world
• Example: a function or method with no return value
13. abstract class Command {
Simplicity }
public virtual void Execute();
C#
abstract class RoverCommand : Command {
Functions as values protected Rover Rover { get; private set; }
public RoverCommand(MarsRover rover) {
this.Rover = rover;
}
F# }
class BrakeCommand : RoverCommand {
type Command = Rover -> unit
public BrakeCommand(Rover rover) : base(rover)
{ }
let BrakeCommand =
public override void Execute() {
fun rover -> rover.Accelerate(-1.0) Rover.Accelerate(-1.0);
}
}
let TurnLeftCommand =
class TurnLeftCommand : RoverCommand {
fun rover -> rover.Rotate(-5.0<degs>) public TurnLeftCommand(Rover rover) : base(rover)
{}
public override void Execute() {
Rover.Rotate(-5.0);
}
}
14. Simplicity
Functional data
let swap (x, y) = (y, x) Tuple<U,T> Swap<T,U>(Tuple<T,U> t)
F# { C#
return new Tuple<U,T>(t.Item2, t.Item1)
}
let rotations (x, y, z) = ReadOnlyCollection<Tuple<T,T,T>> Rotations<T>
(Tuple<T,T,T> t)
[ (x, y, z); {
(z, x, y); new ReadOnlyCollection<int>
(new Tuple<T,T,T>[]
(y, z, x) ] { new Tuple<T,T,T>(t.Item1,t.Item2,t.Item3);
new Tuple<T,T,T>(t.Item3,t.Item1,t.Item2);
new Tuple<T,T,T>(t.Item2,t.Item3,t.Item1); });
}
let reduce f (x, y, z) = int Reduce<T>(Func<T,int> f,Tuple<T,T,T> t)
{
f x + f y + f z return f(t.Item1) + f(t.Item2) + f (t.Item3);
}
21. Challenges
• Impedance mismatch with statically-typed languages
• Need to manually integrate codegen tools with build
process, source control, etc.
• No elegant way to handle schema change
• Loss of type information due to up-casts to Object, or
even have to just parse strings
22. But…
• Data sources often have rich schemas and associated
data definitions
• Static types should make your experience better, not
worse!
25. Type provider
IDE Compiler
IntelliSense for
Type-Check Compile using
Generated
Imported Types Type Provider
Types
26. Demo summary
• Can program against web-scale schematized data
• code gen would never work here!
• Don’t have to wait for codegen or code to compile
• With typechecking!
• Can detect schema change
• With great Visual Studio tooling!
28. What’s next for F#?
• Cloud, cloud cloud!
• Make F# programming on Azure even easier
• Can use F# computation expressions to add new syntax
in a library
• for example, cloud { … }
• F# async and query expressions are not built-in
syntax—they use computation expressions
30. Cloud Numerics
• Extensive library of numerical algorithms
• Ranges from basic math to advanced statistics to linear algebra
• Supports distributed arrays and computation
• Can deploy to Azure when lots of compute resources are
needed
Notas del editor
have linq, have create way to manipulate data, but how do you get the schema?
who here has used one of these apis?
show how cloud numerics solves a problem“how would you do numerical analysis on large quantities of data?”(be interactive)- connect to problems they are already working on- “show how sausage is made” : what were we thinking in design?- type providers are linq on steroids