-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRecords.fold
113 lines (68 loc) · 2.03 KB
/
Records.fold
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
-- A static record is simply a list of bindings.
type Pair a = { first::a, second::a }
Pair :: first: a -> second: a -> Pair a
p1 :: Pair Int = Pair (23, 22)
p2 :: Pair Str = Pair ("Hello", "Hey")
-- // --
type Pair T = (first: T, second: T)
Pair : {T : Eq, -> (first: T, second: T) -> Pair T
p1 : Pair Int = Pair (23, 22)
p2 : Pair Str = Pair ("Hello", "Hey")
-- Collection Access Operator
-- Record access
p2.first == "Hello"
p2:first == "Hello"
p2#first == "Hello"
p2/first == "Hello"
-- Module access
List.length [1, 2, 3, 4, 5]
List:length [1, 2, 3, 4, 5]
List#length [1, 2, 3, 4, 5]
List/length [1, 2, 3, 4, 5]
-- List access
[1, 2, 3, 4] . length
[1, 2, 3, 4] : length
[1, 2, 3, 4] # length
[1, 2, 3, 4] / length
-- Inverse function application
distances_by_class . transpose >> sort >> take k >> map (#2) >> flatten
distances_by_class : transpose >> sort >> take k >> map (#2) >> flatten
distances_by_class >> transpose >> sort >> take k >> map (#2) >> flatten
distances_by_class / transpose >> sort >> take k >> map (#2) >> flatten
[1 2 3 4] # 3
(# [1 2 [3, 2, 1] 4] 3 1)
[1 2 [3, 2, 1] 4] # 3 1
[1 2 [3, 2, 1] 4] # [1..3] 2
[1 2 [3, 2, 1] 4] # [1..3] # 2
([1 2 [3, 2, 1] 4] # [1..3]) # 2
{1: [1, 3] 2: ..., 3: ... 4} # [1..3]
=>
(((system :fetcher) :session) :conf)
(-> system :fetcher :session :conf)
-- // --
type Person = String Int
showPerson : Person -> String
showPerson p = let MkPerson name age = p in
name ++ " is " ++ show age ++ " years
old"
alan = { name: "Alan Turing", age: 32 }
alan = { name: "Alan Turing" age: 32 }
-- // --
type Person = (String, Int)
showPerson : Person -> String
showPerson p =
let Person (name, age) = p in
name ++ " is " ++ show age ++ " years old"
alan = { name: "Alan Turing", age: 32 }
alan = { name: "Alan Turing" age: 32 }
get_older self =
{ self | age <- self.age + 1 }
open Engine
open Web.Engine
open Web_Utils
type Event = {
name :: String
kind :: String
description :: String
location :: String
}