projects:fsharp_workshop
Table of Contents
F# workshop
Prerequisites
- https://www.linqpad.net/ or anything that can execute a REPL1)
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
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.
Getting data
The following example loads data from webpage and stores it in CSV file.
An F# type provider is a component that provides types, properties, and methods for use in your program.
The key to information-rich programming is to eliminate barriers to working with diverse information sources. One significant barrier to including a source of information into a program is the need to represent that information as types, properties, and methods for use in a programming language environment.
Writing these types manually is very time-consuming and difficult to maintain. A common alternative is to use a code generator which adds files to your project; however, the conventional types of code generation do not integrate well into exploratory modes of programming supported by F# because the generated code must be replaced each time a service reference is adjusted.
References
1)
Read, Evaluate, Print Loop
projects/fsharp_workshop.txt · Last modified: 2015/05/02 12:45 by mkucia