SAFE Stack workshop

Full stack web development in F#

by Zaid Ajaj

About Me

  • Zaid Ajaj

  • Originally from Iraq

  • Living in the Netherlands

  • Lead Developer at eSightMonitoring

  • Working with C#, Javascript, F# and SQL

  • Active OSS contibutor to everything F#-related

  • Author of The Elmish Book

  • Follow me on Twitter & Github for F# news and latest developments

Table Of Contents

  • What is F#?

  • Why learn and use F#?

  • Getting started

  • Functional thinking

  • Unit testing

  • Data access

  • Beginning SAFE-Stack

What is F#?

  • Functional-first programming language

  • Part of .NET

  • Based on OCaml

  • Statically typed

Why learn F#?

  • Focus on simplicity

  • Focus on correctness

  • Fully featured core library

  • Powerful type-system that works for you!

  • Safe by default (unless you want otherwise)

  • Different way of thinking about problems

  • Huge set of available libraries from .NET and F#

  • Use everywhere: desktop, web backend, web frontend, mobile etc.

Getting started with F#!

  • Use dotnet CLI

  • F# interactive

  • Use any editor: Visual Studio, VS Code or Rider

  • Visual Studio + F# Interactive is a great place to learn

  • Building a console application

  • F# basics

Using dotnet CLI

Starting F# Interactive

dotnet fsi

Creating a new console application

dotnet new console -lang F#

Building and running the application

dotnet run

Adding nuget packages

dotnet add package [package-name]

F# Basics

  • Value assignment, function declaration

  • Expressions everywhere and type-inference

  • Conditionals

  • Lists, arrays and sequences

  • The |> forward pipe operator

  • Record types

  • Union types

  • Pattern matching

Applied Functional Programming

Demonstrating idiomatic functional code:

  • Parsing strings as integers

  • Modelling shapes with unions

  • Recursive shapes

Unit Testing with F#:

Data access with F#:

Beginning SAFE-Stack

  • Full Stack F# web development

  • Backend built on AspNet Core via Giraffe and Saturn

  • Frontend built on React via Feliz and Elmish

  • Compiling to Javascript using Fable

  • Modern intergration with the JS ecosystem

  • Fable already has a large set of bindings

  • Using SAFE.Simplified template

  • Abstracting HTTP/JSON away with Fable.Remoting

SAFE-Stack Templates:

Thanks for having me!

  • See you next time.

  • Questions?