One of the following should be enough for you to run the exercises:
- Visual Studio 2013 / 2015 (Windows only).
- If you already have Visual Studio, you may need to download and install F# explicitly.
- Xamarin Studio (OS/X or Windows).
- MonoDevelop (Linux, OS/X or Windows).
- Vagrant and VirtualBox simply by running
vagrant upin the root of the repository.
Here are some guidelines as to how the workshop will be broken down:
| Start time | Exercise | Files |
|---|---|---|
| 09:00 | Introductions, setup your REPL | |
| 09:30 | Functions, the core of the language! | functions.fsx |
| 10.30 | Tuples | tuples.fsx |
| 11.00 | Coffee break | |
| 11.15 | Records | records.fsx |
| 11.45 | Discriminated unions & pattern matching (part 1) | ADT1.fsx ADT2.fsx ADT3.fsx ADT4.fsx |
| 12.15 | Lunch | |
| 13.00 | Recap of concepts covered so far, opportunity to ask questions | |
| 13.30 | Discriminated unions & pattern matching (part 2) | pattern_matching1.fsx pattern_matching2.fsx |
| 14.15 | Working with lists | lists1.fsx lists2.fsx lists3.fsx lists4.fsx |
| 15.15 | Break | |
| 15.30 | Real world example: form validation for a web application | profiles |
The project in the profiles folder is a simple web project that implements simple API validation using the suave web framework:
- The validation should be implemented in
profiles.server/Profile1.fs. The sample provided shows validating that the firstname is a required field. - Tests for all validations are provided in
profiles.tests/Profile1Tests.fs. You should keep adding validations until all the tests pass.
To run the tests:
- Lin:
./build.sh RunTests - Windows:
./build.cmd RunTests
To run the web app:
- Linux:
./build.sh Run - Windows:
./build.cmd Run
The site should be available on http://localhost:3000.
Some useful functions:
Char.IsDigit : char -> boolChar.IsLetter : char -> boolString.Concat : seq<'t> -> string
Also remember that string is a sequence of characters. For example the following expression results in the string "1":\
"profile1" |> Seq.filter Char.IsDigit |> String.ConcatThe project in the life folder is a suave based game of life web application with some critical elements removed.
The UI is a modified version of http://www.julianpulgarin.com/canvaslife/ that moves the computation to the server.
Several critical elements have been removed and are left as an exercise:
- The easiest missing piece is to enable the sample patterns to be loaded. You should use the dataStore to load the pattern and return it as the response body (
Life.Server/Program.fs). - The next piece is to implement the game of life algorithm. The web part of this has been wired up for you but the implementation in:
Life.Server/Game.fsis missing. - The final piece is enable patterns to be saved:
- You will need to implement the run length encoding algorithm:
Life.Server/RLE.fs. - You will then need to implement the PUT endpoint:
Life.Server/Program.fs.
Make use of the Life.Tests project that already has xUnit configured.
To run the tests:
- Linux:
./build.sh RunTests - Windows:
./build.cmd RunTests
To run the web app and restart the server when source changes:
- Linux:
./build.sh Watch - Windows:
./build.cmd Watch