With a pre-recorded presentation, we explore the unique features that F# offers to functional developers: functions, composition, piping, discriminated unions, active patterns and computation expressions.
Followup and Q&A is by domain expert Andre Dublin who elaborates on the details and demonstrates the F# IDE's type discrimination features.
This presentation is technical and intended for developers and students.
presentation example code:
let add a b = a + b
let increment = add 1
// infers that a and b are ints
let f a b = a + b
// auto generalization because a and b are generic and must implement the comparision interface
let max a b = if a > b then a else b
max 1 2
max "A" "B"
let makeTuple a b = (a, b)
type PersonA = {
Name : string
Age : int
}
let person = {
Name = "Andre"
Age = 35
}
//type PersonB = {
// Name : string
// Age : int
//}
let updatePersonAge person =
{ person with Age = 35 }
let updatePersonName person =
{ person with Name = "Andre Dublin" }
//let newPerson = updatePersonAge person 36
//let newPersonB = updatePersonName newPerson "Andre Dublin"
// super simple example of function composition
let updatePerson = updatePersonAge >> updatePersonName
let newPerson = updatePerson person
// using an either monad to represent good or bad state
// see http://fsharpforfunandprofit.com/rop/
// see https://github.com/fsprojects/Chessie
// see https://github.com/swlaschin/Railway-Oriented-Programming-Example
type Result<'TEntity> =
| Success of 'TEntity
| Failure of string