Skip to content

Commit 91be8bb

Browse files
committed
Dict syntax with assoc literals
1 parent 6d06b83 commit 91be8bb

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

Dictionaries.fold

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,23 @@
55
type Dict k v = List (k, v)
66

77

8-
OrdMap [k1 => v2, k2 => v2, ..., kn => vn]
8+
val x = Map.new [k1 => v2, k2 => v2, ..., kn => vn]
99

1010

1111
-- Dictionary is a hash-map
1212

1313
type Person =
14-
{ name :: String
15-
age :: Int
14+
{ name :: String,
15+
age :: Int,
1616
city :: City }
1717

18-
dylan :: Person =
19-
{ name => "Bob Dylan"
20-
age => 32
21-
city => `London }
22-
23-
dylan :: Person =
24-
{ name = "Bob Dylan"
25-
age = 32
18+
val dylan :: Person =
19+
{ name = "Bob Dylan",
20+
age = 32,
2621
city = `London }
2722

28-
dylan :: Person =
29-
{ name: "Bob Dylan"
30-
age: 32
31-
city: `London }
32-
33-
|| There are also structural run-time types (row polymorphism) that do not
34-
|| require type definition.
23+
-- There are also structural run-time types (row polymorphism) that do not
24+
-- require type definition.
3525

3626
p1 = { `x => 231, `y => 500 }
3727

@@ -40,8 +30,7 @@ p1 = { `x => 231, `y => 500 }
4030
coordinate = `x => 23
4131

4232

43-
people |> fold init: [] do (name => person) ->
44-
45-
end
33+
people_by_name
34+
|> fold (acc (name, p) -> [p.age & acc]) []
4635

4736

0 commit comments

Comments
 (0)