diff --git a/FSharpKoans/AboutBinding.fs b/FSharpKoans/AboutBinding.fs index 91b88d66..f1715431 100644 --- a/FSharpKoans/AboutBinding.fs +++ b/FSharpKoans/AboutBinding.fs @@ -60,21 +60,21 @@ module ``02: About Binding`` = [] let ``01 Basic 'let' binding`` () = let x = 50 in // note that the syntax is more explicit about what's really going on! - x |> should equal __ + x |> should equal 50 [] let ``02 Equivalent basic 'let' binding`` () = // this is exactly equivalent to the previous binding. let x = 50 - x |> should equal __ + x |> should equal 50 [] let ``03 There are many types of values`` () = - let a = __ - let b = __ - let c = __ - let d = __ - let e = __ - let f = __ + let a = 7 + let b = 4.5 + let c = true + let d = "Hi" + let e = 'e' + let f = () a |> should be ofType b |> should be ofType c |> should be ofType @@ -84,16 +84,16 @@ module ``02: About Binding`` = [] let ``04 We can compare values using F#'s comparison operators`` () = - 1 |???| 2 |> should equal true // change the |???| to be an actual operator - 2 |???| 1 |> should equal true - 1 |???| 1 |> should equal true - 1 |???| 1 |> should equal false - () |???| () |> should equal true - () |???| () |> should equal false + 1 < 2 |> should equal true // change the |???| to be an actual operator + 2 > 1 |> should equal true + 1 = 1 |> should equal true + 1 < 1 |> should equal false + () = () |> should equal true + () > () |> should equal false [] let ``05 There's a `not` function instead of a `not` operator`` () = - __ true |> should equal false + not true |> should equal false [] let ``06 Nest your 'let' statements as deeply as you'd like`` () = @@ -103,7 +103,7 @@ module ``02: About Binding`` = let d = 63 in d c + 1 b + 7 - a |> should equal ___ + a |> should equal 71 (* Identifiers are *referentially transparent*: the link between value and identifier never changes. @@ -139,9 +139,9 @@ module ``02: About Binding`` = 3 + a let c = a + 4 let a = a + a - a |> should equal __ - b |> should equal __ - c |> should equal __ + a |> should equal 42 + b |> should equal 11 + c |> should equal 25 (* @@ -155,36 +155,36 @@ module ``02: About Binding`` = [] let ``08 An identifier pattern will match anything`` () = - let x = __ // replace with an integer - let y = __ // replace with a string - let z = __ // replace with anything else! + let x = 11 // replace with an integer + let y = "hello" // replace with a string + let z = 'h' // replace with anything else! x |> should be ofType y |> should be ofType [] let ``09 A wildcard pattern will match anything`` () = - let _ = __ // replace with an integer - let _ = __ // replace with a string - let _ = __ // replace with anything else! + let _ = 45 // replace with an integer + let _ = "hhhuh" // replace with a string + let _ = true // replace with anything else! () [] let ``10 Constant patterns succeed if both sides match`` () = - let 900 = __ - let "Can't win all the time" = __ + let 900 = 900 + let "Can't win all the time" = "Can't win all the time" () [] let ``11 Constant patterns fail if the sides don't match exactly`` () = // fill in something below, on the right-hand side, to make this pattern FAIL - (fun () -> - let "FILL ME IN" = FILL__ME_IN - () + (fun () -> + let "FILL ME IN" = failwith "cannot match" + () ) |> should throw typeof [] let ``12 Or patterns succeed if any pattern matches`` () = - let a | a = __ - let 7 | 13 | 2 = 3 + __ - let 'x' | _ | 'p' = __ + let a | a = 'a' + let 7 | 13 | 2 = 3 + 4 + let 'x' | _ | 'p' = 'p' () \ No newline at end of file diff --git a/FSharpKoans/AboutFunctions.fs b/FSharpKoans/AboutFunctions.fs index ecb705b0..f43034c1 100755 --- a/FSharpKoans/AboutFunctions.fs +++ b/FSharpKoans/AboutFunctions.fs @@ -18,29 +18,29 @@ open NUnit.Framework module ``03: Putting the Function into Functional Programming`` = [] let ``01 A function takes one input and produces one output`` () = - (fun a -> a + 100) __ |> should equal 2097 + (fun a -> a + 100) 1997 |> should equal 2097 [] let ``02 The input to a function is a pattern (Part 1).`` () = - (fun 7 -> 9) __ |> should equal 9 + (fun 7 -> 9) 7 |> should equal 9 [] let ``03 The input to a function is a pattern (Part 2).`` () = - (fun _ -> 75) __ |> should equal 75 + (fun _ -> 75) 4 |> should equal 75 [] let ``04 The input to a function is a pattern (Part 3).`` () = - (fun (2 | 3 | 5) -> "Prime") __ |> should equal "Prime" + (fun (2 | 3 | 5) -> "Prime") 3 |> should equal "Prime" [] let ``05 A function can be bound to a name (Part 1).`` () = let one_third = fun ka -> ka / 3 - __ 21 |> should equal 7 + one_third 21 |> should equal 7 [] let ``06 A function can be bound to a name (Part 2).`` () = let pinky bleh = bleh / 3 // The syntax has changed from Part 1, but the meaning is the same - __ 21 |> should equal 7 + pinky 21 |> should equal 7 [] let ``07 A function can span multiple lines (Part 1).`` () = @@ -48,14 +48,14 @@ module ``03: Putting the Function into Functional Programming`` = let k = "swash" // notice the indentation. let b = "buckle" // F# is whitespace-sensitive, so it is important! zorro + " likes to " + k + b - ) "Zorro the pirate" |> should equal __ + ) "Zorro the pirate" |> should equal "Zorro the pirate likes to swashbuckle" [] let ``08 A function can span multiple lines (Part 2).`` () = let jorus who = let p = 5 who * p - jorus 12 |> should equal __ + jorus 12 |> should equal 60 [] let ``09 A function can span multiple lines (Part 2, expanded syntax).`` () = @@ -66,7 +66,7 @@ module ``03: Putting the Function into Functional Programming`` = let p = 3 in who * p in - jorus 12 |> should equal __ + jorus 12 |> should equal 60 // The next few are very similar. Resist the temptation to // just fill out values without having any idea about what's @@ -79,28 +79,28 @@ module ``03: Putting the Function into Functional Programming`` = // read the above as: fun love -> (fun hate -> (love - hate)) let j = i 10 let k = j 9 - k |> should equal __ + k |> should equal 1 [] let ``11 A function can return a function (Part 2).`` () = let funky a b = a + b let j = funky 10 let k = j 9 - k |> should equal __ + k |> should equal 19 [] let ``12 You can write a function as a one-liner (Part 1).`` () = - (fun ___ -> fun ___ -> __ * __) __ __ |> should equal 27 + (fun a -> fun b -> a * b) 3 9 |> should equal 27 [] let ``13 You can write a function as a one-liner (Part 2).`` () = - (fun _____ ____ -> __ + __) __ __ |> should equal 17 + (fun a b -> a + b) 10 7 |> should equal 17 [] let ``14 'Multiple-argument' functions are one-input, one-output in disguise`` () = let i j k = j * k - let j = __ 4 - let k = __ 12 + let j = i 4 + let k = j 12 k |> should equal 48 [] @@ -108,7 +108,7 @@ module ``03: Putting the Function into Functional Programming`` = let f a = failwith "An exception will be thrown as soon as this is executed." a + 2 - ___ |> should be ofType int> + f |> should be ofType int> [] let ``16 A function is executed when it is called, NOT when it is defined or referenced (Part 2).`` () = @@ -123,7 +123,7 @@ module ``03: Putting the Function into Functional Programming`` = let ``17 Two names can be bound to the same value`` () = let f x = x + 2 let y = f - y 20 |> should equal ___ + y 20 |> should equal 22 [] @@ -131,8 +131,8 @@ module ``03: Putting the Function into Functional Programming`` = let a = 25 let f () = a + 10 let a = 99 - a |> should equal __ - f () |> should equal __ + a |> should equal 99 + f () |> should equal 35 [] let ``19 Nesting functions`` () = @@ -140,14 +140,14 @@ module ``03: Putting the Function into Functional Programming`` = let triple x = x * 3 let addOne x = x + 1 addOne (triple x) - hailstone 5 |> should equal __ + hailstone 5 |> should equal 16 [] let ``20 Functions have types`` () = let a x y = x + "cabbage" + y let b r = 50.0 / r - a |> should be ofType - b |> should be ofType + a |> should be ofType + b |> should be ofType [] @@ -178,11 +178,11 @@ module ``03: Putting the Function into Functional Programming`` = [] let ``22 Operators are functions in disguise`` () = - (+) 5 8 |> should equal __ - (-) 3 5 |> should equal __ - (/) 12 4 |> should equal __ - (=) 93.1 93.12 |> should equal __ - (<) "hey" "jude" |> should equal __ + (+) 5 8 |> should equal 13 + (-) 3 5 |> should equal -2 + (/) 12 4 |> should equal 3 + (=) 93.1 93.12 |> should equal false + (<) "hey" "jude" |> should equal true // ... and other operators: >, <=, >=, <>, %, ... (* diff --git a/FSharpKoans/AboutTesting.fs b/FSharpKoans/AboutTesting.fs index 1361ba4b..9dfffc0a 100644 --- a/FSharpKoans/AboutTesting.fs +++ b/FSharpKoans/AboutTesting.fs @@ -48,9 +48,9 @@ module ``01: About Testing`` = [] let ``01 How this works`` () = // In F#, any sequence of characters between `` marks can be identifiers. ``This is a long method name`` is way better than ThisIsALongMethodName ! let expected_value = 1 + 1 - let actual_value = __ //start by changing this line + let actual_value = 2 //start by changing this line actual_value |> should equal expected_value // Easy, right? Now try one more. [] - let ``02 Fill in the values`` () = (1 + 1) |> should equal __ + let ``02 Fill in the values`` () = (1 + 1) |> should equal 2 diff --git a/FSharpKoans/FSharpKoans.fsproj b/FSharpKoans/FSharpKoans.fsproj index 7f644ab5..3ab8cd21 100755 --- a/FSharpKoans/FSharpKoans.fsproj +++ b/FSharpKoans/FSharpKoans.fsproj @@ -1,11 +1,11 @@ - - - - netcoreapp2.2 - - false - - + + + + netcoreapp2.2 + + false + + @@ -22,13 +22,13 @@ - - - - - - - - - + + + + + + + + + \ No newline at end of file