F# eye for the Haskell weenie
Phillip Trelford, @ptrelford
London Haskell, 2015
F#
• Statically Typed
• Functional First
• Object Oriented
• Open Source
• Cross Platform
• In Visual Studio
& Xamarin Studio
& Emacs & Vim & Atom & ..
F# Influences
// OCaml + Python like light syntax
let dist (x1,y1) (x2,y2) =
let x = x1 - x2 in
let y = y2 - y1 in
sqrt (x * x + y * y)
// & C# dot-driven development
let trim (s:string) =
s.Trim() F#
OCaml
Python
C#
Miranda Haskell
Haskell
Miranda
Type
Classes
Monads
Change of syntax for type declarations
— Miranda
bool ::= True | False
string == [char]
becomes in Haskell
data Bool = False | True
type String = [Char]
Some History of Functional Programming Languages, Turner
F# Community
Phillip Trelford, @ptrelford
London Haskell, 2015
F#unctional Londoners
• meetup.com/fsharplondon
• 1000+ Members
• Meets every 2 weeks
• Topics
• Machine Learning
• Finance
• Games
• Art
• Cloud
• Web
F# Software Foundation
http://www.fsharp.org
software stacks
trainings teaching F# user groups snippets
mac and linux cross-platform books and tutorials
F# community open-source MonoDevelop
contributions research support
consultancy mailing list
F# Testimonials
order of magnitude increase in productivity
GameSys
performance is 10× better than the C++ that it replaces
Aviva
I am still waiting for the first bug to come in
E-On
Source: fsharp.org/testimonials
F# startups: Jet.com $570M raised
Onikira – Demon Killer: available on Steam
Live Demos: Bread & Butter stuff
Phil Trelford, @ptrelford
F# eye for the Haskell weenie
Functions
let rec fact x =
if x < 1 then 1
else x * fact (x - 1)
let rec fib = function
| 0 -> 0 | 1 -> 1
| n -> fib(n - 1) + fib(n - 2)
[1..3] |> List.map ((+)1)
let inline map xs = List.map xs
map ((+)1) [1..3]
Sum types
Type definition
type Shape =
| Circle of radius:float
| Rectangle of width:float * height:float
Pattern matching
match shape with
| Circle(r) -> 2.0 * r
| Rectangle(_, h) -> h
Active Patterns
let (|FormulaText|_|) (s:string) =
if s.StartsWith "=" then Some(s.Substring(1))
else None
let (|NumberValue|_|) (s:string) =
match System.Decimal.TryParse(s) with
| true, n -> Some(n)
| false, _ -> None
let parse = function
| FormulaText text -> Formula text
| NumberValue n -> Number n
| _ -> invalidOp "Unexpected text"
Live Demos: Familiar concepts
Phillip Trelford, @ptrelford
London Haskell, 2015
packages |> map
• Cabal -> Paket
• Shake -> Fake
• Parsec -> FParsec
• QuickCheck -> FsCheck
• HappStack -> Suave
• gchjs -> WebSharper
• Idris -> F*
Turtle Computation Expression
let british = turtle {
LIFT THE PEN UP
WALK 4 STEPS
TURN 3 GRADATIONS TO THE RIGHT
PICK THE GREEN PEN
PUT THE PEN DOWN
DO AS leonardo
LIFT THE PEN UP
WALK 4 STEPS
PICK THE RED PEN
PUT THE PEN DOWN
REPEAT 3 TIMES WHAT leonardo DOES
}
M-Brace cloud Computation Expression
Operator overloading
let (<*>><) a b = a + " approves " + b
"Fish" <*>>< "custom operators!"
Elm’s Mario Tutorial in F# with FunScript
Pointless free programming
let step dir mario =
mario |> physics |> walk dir |> gravity |> jump dir
let step dir =
physics >> walk dir >> gravity >> jump dir
Live Demos: Type Providers
Phillip Trelford, @ptrelford
London Haskell, 2015
Type providers: JSON
open FSharp.Data
type Simple = JsonProvider<""" { "name":"John", "age":94 } """>
let simple = Simple.GetSample()
simple.Age
R – TYPE PROVIDER
World bank data with FunScript
Live Demos: Apps & Games
Phillip Trelford, @ptrelford
London Haskell, 2015
Cross Platform Games
Path to Go | XBLA Pissed off Owls| iOS Pool | WebGL
http://tinyurl.com/funbasi
c
FUN BASIC - WINDOWS
STORE APP
Live Debugging
Profiling with YourKit
Resources
Phillip Trelford, @ptrelford
London Haskell, 2015
Meet the F#ers on Twitter: #fsharp
@rickasaurus
@tomaspetricek
@jonharrop
#FsAdvent#FSharp
Buy the Book
Questions or Pub?
• Twitter
• @ptrelford
• Blog
• http://trelford.com/blog

FSharp eye for the Haskell guy - London 2015

Editor's Notes

  • #2 “extreme confidence in their own productivity is a hallmark of LISP Weenies and Insufferable Haskell Pricks”-  http://sdtimes.com/code-watch-functional-programmings-smugness-problem/#ixzz3sL5eeHWo  https://www.quora.com/Why-is-Haskell-considered-such-a-nice-and-great-language-yet-is-not-being-used https://www.quora.com/Functional-Programming/Which-of-Haskell-and-OCaml-is-more-practical
  • #5 http://www.cs.kent.ac.uk/people/staff/dat/tfp12/tfp12.pdf
  • #10 http://techgroup.jet.com/index.html https://www.crunchbase.com/organization/jet#/entity
  • #11 http://store.steampowered.com/app/310850/
  • #16 https://twitter.com/leebeattie/status/660005167337730048
  • #18 http://www.pirrmann.net/fun-with-turtles/
  • #20 https://twitter.com/tomaspetricek/status/408301566559412224
  • #34 https://sergeytihon.wordpress.com/2015/10/25/f-advent-calendar-in-english-2015/