-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path3_do_notation.hs
More file actions
47 lines (36 loc) · 1.26 KB
/
Copy path3_do_notation.hs
File metadata and controls
47 lines (36 loc) · 1.26 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
data Project = Project
type Net = Int
type Tax = Int
type Gross = Int
calculateNet :: Project -> Maybe Net
calculateNet = undefined
calculateTax :: Project -> Net -> Maybe Tax
calculateTax = undefined
calculateGross :: Net -> Tax -> Maybe Gross
calculateGross = undefined
calculatePriceDoNotation :: Project -> Maybe (Net, Tax, Gross)
calculatePriceDoNotation project = do
net <- calculateNet project
tax <- calculateTax project net
gross <- calculateGross net tax
return (net, tax, gross)
-- looks something like that in C# (LINQ)
-- NetTaxGross netTaxGross =
-- from net in calculateNet(project)
-- from tax in calculateTax(project, net)
-- from gross in calculateGross(net, tax)
-- select new NetTaxGross(net, tax, gross);
-- looks something like that in F# (computation expressions)
-- netTaxGross = optional {
-- let! net = calculateNet(project)
-- let! tax = calculateTax(project, net)
-- let! gross = calculateGross(net, tax)
-- some(net, tax, gross)
-- }
-- looks something like that in Kotlin + Arrow (suspend functions)
-- val netTaxGross = optional<NetTaxGross> {
-- val net = calculateNet(project).bind()
-- val tax = calculateTax(project, net).bind()
-- val gross = calculateGross(net, tax).bind()
-- Triple(net, tax, gross)
-- }