-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAboutModules.fs
More file actions
58 lines (45 loc) · 1.69 KB
/
AboutModules.fs
File metadata and controls
58 lines (45 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
namespace FSharpKoans
open FSharpKoans.Core
module MushroomKingdom =
type Power =
| Mushroom
| Star
| FireFlower
type Character = {
Name: string
Occupation: string
Power: Power option
}
let Mario = { Name = "Mario"; Occupation = "Plumber"; Power = None}
let powerUp character =
{ character with Power = Some Mushroom }
//---------------------------------------------------------------
// About Modules
//
// Modules are used to group functions, values, and types.
// They're similar to .NET namespaces, but they have slightly
// different semantics as you'll see below.
//---------------------------------------------------------------
[<Koan(Sort = 19)>]
module ``about modules`` =
[<Koan>]
let ModulesCanContainValuesAndTypes() =
AssertEquality MushroomKingdom.Mario.Name __
AssertEquality MushroomKingdom.Mario.Occupation __
let moduleType = MushroomKingdom.Mario.GetType()
AssertEquality moduleType typeof<FILL_ME_IN>
[<Koan>]
let ModulesCanContainFunctions() =
let superMario = MushroomKingdom.powerUp MushroomKingdom.Mario
AssertEquality superMario.Power __
(* NOTE: In previous sections, you've seen modules like List and Option that
contain useful functions for dealing with List types and Option types
respectively. *)
open MushroomKingdom
[<Koan(Sort = 20)>]
module ``about opened modules`` =
[<Koan>]
let OpenedModulesBringTheirContentsInScope() =
AssertEquality Mario.Name __
AssertEquality Mario.Occupation __
AssertEquality Mario.Power __