Learn about pattern matching and recursion by creating a your own list using the discriminated union!
Install the .NET5 SDK.
Clone this git repository.
Use the following command to restore the tool.
dotnet tool restore
Start the test runner.
dotnet watch run -p test
If you are using Visual Studio, you can also test it from Test Explorer.
At first, all tests are pending.
Open the file TernaryTest.fs
in the ListDojo.Test
project and remove one of the prefixes p
.
- ptestList "tnot properties" [
+ testList "tnot properties" [
Open the TernaryDojo.fs
file in the ListDojo
project and implement the tnot
function.
- let tnot a = Hole?implement_tnot
+ let tnot a =
+ match a with
+ | False -> True
+ | Null -> Null
+ | True -> False
Confirm that the test passes.
Repeat this process to pass all the test cases!
- Remove one
p
prefix from the test file. - Implement the function to be tested.
- Confirm that the test passes.
TernaryDojo
- You will create your own tiny library for three-valued logic and learn about the basic use of discriminated unions and pattern matching.
OptionDojo
- You will create your own
option
type, which is a type for safely handlingnull
, and learn that discriminated unions are more useful than mere enums.
- You will create your own
ListDojo
- You will create your own
list
type using a discriminated union. Topics such as tail-recursion will also be covered.
- You will create your own
The p
stands for pending.
The prefix p
can be removed to include it in the test as below.
ptestList
->testList
ptestCase
->testCase
ptestProperty
->testProperty