File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ -- This encoding of brossa supports:
2+ --
3+ -- * defaulted datapoints
4+ -- * derived datapoints
5+ -- * parametrized datapoints
6+ -- * collectable datapoints, with defaults
7+
8+ main = do
9+
10+ -- hydration:
11+ let record :: Main.M = Function.fix $
12+ Record.set @"x" 500 .
13+ Record.set @"y" 28 .
14+ Record.modify @"sov_country" (Main.add_param_values [(1234, "France")]) .
15+ Main.view
16+
17+ -- access:
18+ IO.print $ Record.get @"x" @Int record
19+ IO.print $ Record.get @"y" @Int record
20+ IO.print $ Record.get @"z" @Int record
21+ IO.print $ (Record.get @"sov_country" @(Int -> Text) record) 5678
22+ IO.print $ (Record.get @"sov_country" @(Int -> Text) record) 1234
23+
24+ data M = M {
25+ x :: Int,
26+ y :: Int,
27+ z :: Int,
28+ sov_country :: Int -> Text
29+ }
30+
31+ view :: Main.M -> Main.M = \me -> Main.M {
32+ -- no default
33+ -- x : Int
34+ x = Error.error "x is obstructed: no value or default",
35+
36+ -- defaulted
37+ -- y : Int = 2
38+ y = 2,
39+
40+ -- defaulted, derived from others
41+ -- z : Int = x + y
42+ z = Int.plus (Record.get @"x" me)
43+ (Record.get @"y" me),
44+
45+ -- parametrized datapoint
46+ sov_country = Main.default_parametrized "sov_country: obstructed"
47+ [(5678, "Germany")]
48+ }
49+
50+ add_param_values = \m f k -> do
51+ let m = Map.fromList m
52+ Maybe.maybe (f k) Function.id (Map.lookup k m)
53+
54+ default_parametrized = \msg vals k -> do
55+ let def = Map.fromList vals
56+ Maybe.maybe (Error.error msg)
57+ Function.id
58+ (Map.lookup k def)
You can’t perform that action at this time.
0 commit comments