-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
PretendModules.re
54 lines (45 loc) · 1.14 KB
/
PretendModules.re
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
/**
# "Pretend" Modules
Sometimes it's useful to pretend your module already exists, and just use it
first to find ergonomic APIs that closely match your domain problem.
For example, if we're building a car dealership app we will need to keep track
of daily appointments that people have made to test-drive some of your cars.
I've found that sketching out what a nice API for this could look like made my
APIs a lot better.
Whenever I reached for good ol' records, unions and lists, to just start
something out, I'd end up with a lot of code that just deals with lists and
records issues instead of dealing with my domain problems directly. Let's see:
*/
type car_status =
| New
| Used(int)
| Sold;
type car = {
name: string,
model: string,
status: car_status,
};
type appointment = {
date: int,
/** unix timestamp */
car,
};
type day =
| Mon
| Tues
| Wed
| Thur
| Fri
| Sat
| Sun;
type schedule = list((day, list(appointment)));
let car_volvo = {name: "Volvo", model: "XC90", status: New};
let schedule = [
(
Mon,
[
{date: 1547475544, car: car_volvo},
{date: 1547476154, car: car_volvo},
],
),
];