computation-expressions-workshop
computation-expressions-workshop copied to clipboard
F# Computation Expressions Workshop
Computation Expressions Workshop
The Computations Expressions Workshop collects and presents the content of several papers and presents the material as a set of tutorials. This content is intended to be used in a workshop setting.
Setting up
The workshop uses the dotnet
CLI as a base case. However, attendees may
elect to use an editor of their choice, though the steps to use those tools
will be omitted from the tutorials.
Install dotnet
- Install the
dotnet
CLI through the .NET Core SDK
NOTE: Some IDEs will also install the dotnet
CLI.
git clone
Workshop Repository
Clone the workshop repository so you have the materials available locally.
Each tutorial is also tagged so that you can reference the finished result if you get stuck.
git clone https://github.com/panesofglass/computation-expressions-workshop
Create a New Expecto Project
Now that you have the basics, you can get started by creating a new project with Expecto.
- Install the Expecto template with
dotnet new -i Expecto.Template
- Create a new project with
dotnet new expecto -lang fsharp
Outline
Introduction
What?
- Computation Expressions
- Query Expressions
Why?
- Reduce arrowhead pattern
- Familiar syntax, e.g.
let
anddo
with extensions:let!
,do!
,return
, etc. - Language integrated queries (LINQ), e.g.
query { for x in source do select x }
- Language extensions without macros
Exercises
- Computation Expressions:
OptionBuilder
- Without a computation expression
-
Return
-
Bind
- Side effects and
Delay
-
Run
ning a delayed computation -
do!
with aunit
result usingCombine
-
if ... then
without anelse
- Combining Results:
ChoiceBuilder
- CEs for Compuations:
StateBuilder
- Without a computation expression
- Side effects passed into a computation
- Differences between "container" and "computation"
- Sequences:
StackBuilder
-
Yield
=Return
-
For
=Bind
- Differences in
Delay
-
- Error Handling, Disposal, and More
-
TryWith
-
TryFinally
-
Using
-
While
-
Quote
-
- Extending Computation Expressions
- Method Overloads
- Adding Custom Extensions
- Query Expressions
- Embedded DSLs
- NuGet
- IL
- Saturn
- Freya