-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetForm.Mixed.fs
177 lines (138 loc) · 4.69 KB
/
SetForm.Mixed.fs
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
namespace Pedro.Limits.SetForm
module Mixed =
// 3.
// Stst types utilize Oo types in their recursive component, thus mixing
// Stst and Oo.
// It can be traversed via inheritance, or pattern matching on non-terminal
// nodes.
// Only terminal nodes are either Oo or Stst, and this dictates how they can
// be reached.
type Oset<'t> (elems: List<Sset<'t>>) =
member this.elems = elems
and SetElement<'t> (x: option<'t>) =
inherit Oset<'t>([])
member this.x = x
// Admits Sets and "Urelements", or Tuples via inheritance
and Sset<'t> = T of option<'t> | S of Oset<'t>
// Unlike Stst, Stuples are Sets. Tuples differ from Sets in their
// cardinality.
type Otuple2<'t>(a: Sset<'t>, b: Sset<'t>) =
inherit Oset<'t>([
a;
Sset.S(Oset<'t>([
a;
b
]))
])
member this.a = a
member this.b = b
type Otuple3<'t>(a: Sset<'t>, b: Sset<'t>, c: Sset<'t>) =
inherit Otuple2<'t>(
Sset.S(Otuple2<'t>(
a,
b
)),
c
)
and Otuple4<'t>(a: Sset<'t>, b: Sset<'t>, c: Sset<'t>, d: Sset<'t>) =
inherit Otuple2<'t>(
Sset.S(Otuple2<'t>(
Sset.S(Otuple2<'t>(
a,
b
)),
c
)),
d
)
// Hitting language limitations.
// Stuple2.T isn't castable into Sset2.T, so Stuple2.T can't be used.
// Sset2.T is the Stst terminus.
// Stuple2.S can only be used as an envelope type to an Otuple hierarchy.
// Inner Tuples are Ssets, so give up Stuples for Stst.
// Admits any size Otuple
// and Stuple2<'t> = T of option<'t> | S of Otuple2<'t>
// Unifying definition of a single Stst type for Sets, Tuples, or others,
// for kicks?
// The unified Stst differs from Sset only by being specific about its
// terminus component as a generic type. But as Otuple and others should be
// child to Sset, Stst should be a Sset for genericity instead, undoing the
// unification.
// If a "variance" happened over S 'otype wouldn't need to be cast.
//type Stst<'otype, 't> = T of option<'t> | S of 'otype
// subtypes as precisely 'otype.
//and OsetUnf<'t> (elems: List<Stst<OsetUnf<'t>, 't>>) =
// member this.elems = elems
//type SetElementUnf<'t> (x: option<'t>) =
// inherit OsetUnf<'t>([])
// member this.x = x
// Going forward, only Osets or Otuples are defined, with Otuples being
// Osets and either of the two being Ssets.
let construct() =
// Terminus with two Stst
Sset.S(Oset<int>([
Sset.T(None);
Sset.T(Some(1))
])) |> ignore
// Terminus with two Oo
Sset.S(Oset<int>([
Sset.S(SetElement(None));
Sset.S(SetElement(Some(1)))
])) |> ignore
// Terminus with one Stst and one Oo
Sset.S(Oset<int>([
Sset.S(SetElement(None));
Sset.T(Some(1))
])) |> ignore
Sset.S(Oset<int>([
Sset.S(SetElement(None));
Sset.S(Oset<int>([
Sset.S(SetElement(Some(1)))
]))
])) |> ignore
Sset.S(Oset<int>([
Sset.T(None);
Sset.S(Oset<int>([
Sset.T(None)
]))
])) |> ignore
Oset<int>([
Sset.T(None)
]) |> ignore
Otuple2<int>(
Sset.T(None),
Sset.T(None)
) |> ignore
Sset.S(Otuple2<int>(
Sset.T(None),
Sset.T(None)
)) |> ignore
Sset.S(Otuple2<int>(
Sset.S(Oset<int>([Sset.T(None)])),
Sset.T(None)
)) |> ignore
Sset.S(Otuple2<int>(
Sset.S(Otuple2<int>(
Sset.T(None),
Sset.S(Oset<int>([Sset.T(None)]))
)),
Sset.T(None)
)) |> ignore
// Complex construction
let _: Sset<int> =
Sset.S(Otuple2<int>(
Sset.S(Otuple2<int>(
Sset.T(Some(1)),
Sset.T(Some(2))
)),
Sset.S(Otuple2<int>(
Sset.S(Otuple2<int>(
Sset.T(Some(3)),
Sset.T(Some(4))
)),
Sset.T(Some(4))
))
))
()
let print() =
()