User Tools

Site Tools


projects:fsharp_workshop

This is an old revision of the document!


F# workshop

Prerequisites

↘ alternatives

↘ alternatives

Agenda

  • hello(x)
  • Type providers (strongly typed)
  • Matching
  • Options

hello(x)

let hello = printf "Hello World"
hello

F# (pronounced “F Sharp”) is

  • Open Source
  • Multi platform
  • Modern, rising popularity
  • Lazy evaluated
  • Reusable
  • Concise (See signal-to-noise ratio)
  • Strongly typed
  • Functional first
    • Use functional to write easy to test and understand code
    • Use imperative for performance and compatibility
    • Use objective for organization and encapsulation
  • Compiled
  • Not suitable for real time (unpredictable performance)
  • Hard to optimize (Functional languages fundamentally don't model how your computer works)
  • Functional first (different thinking process, you will need to re-learn)

programming language for writing simple code to solve complex problems.

let hello x = printfn "Hello %s" x
hello "world"

Introducing pipeline operator:

let hello x = printfn "Hello %s" x
"World" |> hello

pipeline operator definition

pipeline operator definition

How to define the operator?

let inline (|>) x f = f x
let square x = x * x
let subtract x y = x - y
let ``complicated stuff`` x =
    printfn "%d" (add 5 (square x))
let ``another complicated stuff`` x =
    x |> square |> subtract 5 |> printfn "%d"
let equation x =
	x 
	|> (fun y -> y * y ) 
	|> (fun y z -> y - z ) 5
	|> printfn "%d"

Note that F# uses indentation to indicate block structure. Find out more here.

References

1)
Read, Evaluate, Print Loop
projects/fsharp_workshop.1429371120.txt.gz · Last modified: 2015/04/18 17:32 by mkucia