F# (F Sharp)An Introductory Look
By Kody Myers
History“Mathematicians stand on each others' shoulders and computer scientists stand on each others' toes.”
- Richard Hamming, 1968 Turing Award recipient
Lambda Calculus (λ-calculus)
• A formalism for representing functions.
• Formulated by Alonzo Church in the 1930s.
• Formed the basis of functional programming.
Early Functional Languages
• Lisp – 1958
• ISWIM (“If you See What I Mean”) – 1966
• Metalanguage (ML) – 1973
• Caml – 1985
• Haskell - 1990
"There are only two kinds of programming languages: those people always bitch about and those nobody uses.”
- Bjarne Stroustrup, Creator of C++
“Why Nobody Uses Functional Languages”
• Article appeared in the ACM SIGPLAN Notices newsletter in 1998 by Philip Wadler.
• Wadler was one of the principal designers of Haskell.
[…] there are a large number of factors that hinder the widespread adoption of functional languages. To be widely used, a language should support interlanguage working, possess extensive libraries, be highly portable, have a stable and easy to install implementation, come with debuggers and profilers, be accompanied by training courses, and have a good track record on previous projects.
-- Philip Wadler
Don Syme
• Principal Researcher at Microsoft Research, Cambridge, UK.
• Was working on generics for C# for the .NET Framework.
• Tasked with finding a functional language that would be a good fit with .NET.
Haskell.NET?
We had a go doing Haskell for .NET. We actually got a long way in doing that, but in the end there is quite a lot of dissonance between Haskell and .NET.
- Don Syme
Okay, How About OCaml.NET, Then?
• OCaml: Objective Caml
• Dialect of Caml.
• Descendent of Metalanguage (ML).
F# 1.0 – May 2005
• Functional programming
• Discriminated unions
• Records
• Tuples
• Pattern matching
• Type abbreviations
• Object programming
• Structs
• Signature files
• Scripting files
• Imperative programming
• Modules (no functors)
• Nested modules
• .NET Interoperability
F# 2.0 – April 2010
• Active patterns
• Units of measure
• Sequence expressions
• Asynchronous programming
• Agent programming
• Extension members
• Named arguments
• Optional arguments
• Array slicing
• Quotations
• Native interoperability
• Computation expressions
F# 3.0 – August 2012
• Type providers
• LINQ query expressions
• CLIMutable attribute
• Triple-quoted strings
• Auto-properties
• Provided units-of-measure
Present Day
F# 3.1 – October 2013
• Named union type fields
• Extensions to array slicing
• Type inference enhancements
**Specification not yet finalized
Currently Active Keywords
abstract
and
as
assert
base
begin
class
default
delegate
do
done
downcast
downto
elif
else
end
exception
extern
false
finally
for
fun
function
global
if
in
inherit
inline
interface
internal
lazy
let
let!
match
member
module
mutable
namespace
new
not
null
of
open
or
override
private
public
rec
return
return!
select
static
struct
then
to
true
try
type
upcast
use
use!
val
void
when
while
with
yield
yield!
Inactive Keywords From OCaml
asr
land
lor
lsl
lsr
lxor
mod
sig
Reserved Keywords for Future Use
atomic
break
checked
component
const
constraint
constructor
continue
eager
event
external
fixed
functor
include
method
mixin
object
parallel
process
protected
pure
sealed
tailcall
trait
virtual
volatile
Introducing your“let-saber”“A more elegant weapon for a more civilized age.”
- Obi Wan Kenobi, Star Wars: A New Hope
“let” Us Begin
let hello = “Hello World!”
let pi = 3.1415926
let isRunning = false
let numList = [1 .. 10]
let vehicle = (2013, “Ford”, “Explorer”, true)
let userId = System.Guid.NewGuid()
Wow, Those Puns Were Terrible
• Yeah, you’re probably right.
• Time to lose these boring slides for awhile.
Advantages of F#
• Highly readable, especially for developers who are already with functional languages and .NET programming.
• Highly writeable, especially developing with the help of the Visual Studio IDE.
• Highly reliable, thanks to the tried and heavily-tested libraries of the .NET Framework.
• Moderately portable to other, non-Windows platforms, thanks to the Mono project.
Disadvantages of F#
• Functional languages require an uncomfortable adjustment to the way programmers normally think about problems.
• Sacrifices a measure of performance in favor of reliability.
• Hasn’t garnered a comparable amount of confidence as the other more well-established languages of the .NET Framework.
• Practical solutions are limited to very specific class of problems.
The Future: F# 4.0+
• Printf on unitized values
• Extension property initializers
• Non-null provided types
• Class names as functions
• Static parameters for provided methods
• Printf interpolation
• Extended #if grammar
• Support for 'fixed'
• Tailcall attribute
• Multiple interface instantiations
• Optional type args
• Params dictionaries
A Sampling of Practical Applications
• Unit conversion
• Power generation load balancing and scheduling
• Insurance risk engine
• Game rules engine
• Website click prediction
• Forensic image comparison
• Genome sequencing
• Game player ranking
let isFSharpUseful = true
Source: http://fsharp.org/testimonials/
Suggested Resources
• Try F# – tryfsharp.org
• The F# Software Foundation – fsharp.org
• F# for fun and profit – fsharpforfunandprofit.com
Top Related