Import Upstream version 20180207
[hcoop/debian/mlton.git] / lib / mlton / set / README
CommitLineData
7f918cf1
CE
1Methods of implementing sets (not in terms of the underlying
2representation, but in terms of the public signature).
3
4Polymorphic Elements
5--------------------------------------------------
6 pass operations on 'a as arguments when needed
7 (e.g. equality when testing for membership)
8This is bad, because it requires me to construct my own recursive
9descent functions. Good because it checks types at compile
10time. Cumbersome, because I must keep passing the helper functions
11everywhere.
12
13What happens if I want a dynamically varying order type of sets?
14This can't possibly work.
15
16Special case
17--------------------
18Use polymorhpism with equality types - this only works if the built
19in equality function is what you want. Furthermore, it does nothing
20when you need functions other than equality (e.g. order relations)
21
22Monomorphic Elements
23--------------------------------------------------
24 Use monomorphism and encode the type of the set in the ML type.
25This requires a new functor application for each new type of set.
26Certainly doesn't work if the order type of the set isn't decided
27until run time.
28This can get very cumbersome. Good because it checks types at
29compile time. Also, it "automatically" constructs the proper
30recursive descent functions when the functors are applied.
31Bad because I can't even express the types of some functions
32(e.g. map) without having two different types (structures) around.
33This would
34be better if I could get it to automatically infer the appropriate
35functor applications based on type inference of the code that uses
36sets. Not quite, not only do I want it to infer the appropriate
37functor applications, I want it to *share* the results of functor
38applications corresponding to objects of the same type.
39
40Monomorphic Elements in a Universal Datatype
41--------------------------------------------------
42Bad because it doesn't check types at compile time. However, one can
43build a layer on top that checks the types at run time.
44This requires a single functor application (if it works at all).
45This requires the user to build a union type for all objects that
46might be members of sets. Furthermore, it doesn't even work if I want
47to include sets as parts of some of my base datatypes. That is, the
48set and base datatypes can't be mutually recursive. Maybe this isn't
49a problem. Can I think of an example where I want this??
50
51This gets very cumbersome, because the programmer must constantly
52inject to and project from the universal datatype.
53Furthermore, it reduces modularity, because all of the objects that
54will ever appear in sets must be collected together in one place to
55define the universal datatype.
56
57I bet you pay a pretty good performance hit both in terms of time and
58space with this approach, because of all of the explicit unions that
59are constructed. --- Wait a second! Could you get away without
60constructing these unions in Scheme? How would be sure that you could
61differentiate among elements? Do you need to be able to
62differentiate in correct programs, or only to aid in debugging?
63When do you ever put things in a union and not know what they are???
64It seems to me that this happens whenever you have polymorphic
65functions that aren't parametric, e.g. print.
66
67Object Oriented
68--------------------------------------------------
69Monomorphic elements that include the appropriate operations.
70I don't like this because each element carries its own equality
71function, but I know I want only a single equality function for the
72whole type, and I can't enforce (or even express) that they are the
73same.
74
75
76Other Considerations
77--------------------------------------------------
78Performance implications?
79How would each of these options work in scheme?
80What other options are there in scheme?