-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetForm.Mixed.Rename.fs
142 lines (116 loc) · 3.35 KB
/
SetForm.Mixed.Rename.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
namespace Pslab.Limits.SetForm
module MixedRename =
// 3b.
// A rename of 3).
type Set<'t> (elems: List<Rec<'t>>) =
member this.elems = elems
and SetElement<'t> (x: option<'t>) =
inherit Set<'t>([])
member this.x = x
and Rec<'t> = Su of Set<'t> | Te of option<'t>
// For Pair Set, use form {a,b} here instead of {{a},{a,b}} for traversal
// as Sets.
type Pair<'t>(a: Rec<'t>, b: Rec<'t>) =
inherit Set<'t>([
a;
b
])
member this.a = a
member this.b = b
type Tuple3<'t>(a: Rec<'t>, b: Rec<'t>, c: Rec<'t>) =
inherit Pair<'t>(
Su(Pair<'t>(
a,
b
)),
c
)
and Tuple4<'t>(a: Rec<'t>, b: Rec<'t>, c: Rec<'t>, d: Rec<'t>) =
inherit Pair<'t>(
Su(Pair<'t>(
Su(Pair<'t>(
a,
b
)),
c
)),
d
)
// Try to avoid a runtime cast from Pair backwards to Set, i.e. when
// traversing over Pairs as Pairs. Abstracts the recursive component.
type Uset<'t> (elems: List<Urec<Uset<'t>, 't>>) =
member this.elems = elems
and Urec<'su, 't> = Usu of 'su | Ute of option<'t>
// .. but it doesn't work because of variance issues which mean Urec<Uset>
// is not a supertype of Urec<Pair>. OCaml could support it.
//type Upair<'t>(a: Urec<Upair<'t>, 't>, b: Urec<Upair<'t>, 't>) =
// inherit Uset<'t>([
// a :> Urec<Uset<'t>, 't>;
// b :> Urec<Uset<'t>, 't>
// ])
// member this.a = a
// member this.b = b
let construct() =
Su(Set<int>([
Te(None);
Te(Some(1))
])) |> ignore
Su(Set<int>([
Su(SetElement(None));
Su(SetElement(Some(1)))
])) |> ignore
Su(Set<int>([
Su(SetElement(None));
Te(Some(1))
])) |> ignore
Su(Set<int>([
Su(SetElement(None));
Su(Set<int>([
Su(SetElement(Some(1)))
]))
])) |> ignore
Su(Set<int>([
Te(None);
Su(Set<int>([
Te(None)
]))
])) |> ignore
Set<int>([
Te(None)
]) |> ignore
Pair<int>(
Te(None),
Te(None)
) |> ignore
Su(Pair<int>(
Te(None),
Te(None)
)) |> ignore
Su(Pair<int>(
Su(Set<int>([Te(None)])),
Te(None)
)) |> ignore
Su(Pair<int>(
Su(Pair<int>(
Te(None),
Su(Set<int>([Te(None)]))
)),
Te(None)
)) |> ignore
let _: Rec<int> =
Su(Pair<int>(
Su(Pair<int>(
Te(Some(1)),
Te(Some(2))
)),
Su(Pair<int>(
Su(Pair<int>(
Te(Some(3)),
Te(Some(4))
)),
Te(Some(5))
))
))
()
let print() =
()