You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/fsharp/language-reference/namespaces.md
+8-6Lines changed: 8 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -82,32 +82,34 @@ type PeelState = Peeled | Unpeeled
82
82
// This exception depends on the type below.
83
83
exception DontSqueezeTheBananaException of Banana
84
84
85
-
type Banana(orientation: Orientation) =
85
+
type Banana(orientation: Orientation) =
86
86
member val IsPeeled = false with get, set
87
87
member val Orientation = orientation with get, set
88
-
member val Sides: PeelState list = [Unpeeled; Unpeeled; Unpeeled; Unpeeled] with get, set
88
+
member val Sides: PeelState list = [Unpeeled; Unpeeled; Unpeeled; Unpeeled] with get, set
89
89
90
90
member self.Peel() = BananaHelpers.peel self // Note the dependency on the BananaHelpers module.
91
91
member self.SqueezeJuiceOut() = raise (DontSqueezeTheBananaException self) // This member depends on the exception above.
92
92
93
93
module BananaHelpers =
94
-
let peel (b: Banana) =
94
+
let peel (banana: Banana) =
95
95
let flip (banana: Banana) =
96
96
match banana.Orientation with
97
97
| Up ->
98
98
banana.Orientation <- Down
99
99
banana
100
100
| Down -> banana
101
101
102
+
// Update the peel state for all sides of the banana.
102
103
let peelSides (banana: Banana) =
103
104
banana.Sides
104
105
|> List.map (function
105
106
| Unpeeled -> Peeled
106
107
| Peeled -> Peeled)
107
108
108
-
match b.Orientation with
109
-
| Up -> b |> flip |> peelSides
110
-
| Down -> b |> peelSides
109
+
// Apply the flipping and peeling logic based on the orientation.
110
+
match banana.Orientation with
111
+
| Up -> banana |> flip |> peelSides
112
+
| Down -> banana |> peelSides
111
113
```
112
114
113
115
Note that the exception `DontSqueezeTheBananaException` and the class `Banana` both refer to each other. Additionally, the module `BananaHelpers` and the class `Banana` also refer to each other. This wouldn't be possible to express in F# if you removed the `rec` keyword from the `MutualReferences` namespace.
0 commit comments