-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathmodule-lang.tex
75 lines (61 loc) · 1.95 KB
/
module-lang.tex
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
\begin{itemize}
\item BatEnum
\begin{itemize}
\item utilities
\begin{ocamlcode}
range ~until:20 3
filter, concat, map, filter_map
(--), (--^) (|>) (@/) (/@)
No_more_elements (*interface for dev to raise (in Enum.make next)*)
icons, lcons, cons
\end{ocamlcode}
\item don't play effects with enum
\item idea??? how about divide enum to two; one is just for iterator
the other is for lazy evaluation. (iterator is lazy???)
\end{itemize}
\item Set (\emph{one comparison, one container})
\begin{ocamlcode}
Set.IntSet
Set.CharSet
Set.RopeSet
Set.NumStringSet
\end{ocamlcode}
for polymorphic set
\begin{ocamlcode}
split
union
empty
add
\end{ocamlcode}
why polymorphic set is dangerous? Because in Haskell, \textit{Eq a =>} is implicitly
you want to make your comparison method is unique, otherwise you
union two sets, how to make sure they use the same comparison, here
we use abstraction types, one comparison, one container
we can not override polymorphic = behavior, polymorphic = is pretty bad practice
for complex data structure, mostly not you want, so write compare by yourself
As follows, compare is the right semantics.
\begin{alternate}
# Set.IntSet.(compare (of_enum (1--5)) (of_enum (List.enum [5;3;4;2;1])));;
- : int = 0
# Set.IntSet.(of_enum (1--5) = of_enum (List.enum [5;3;4;2;1]));;
- : bool = false
\end{alternate}
\item caveat
\begin{itemize}
\item module syntax
\begin{ocamlcode}
module Enum = struct
include Enum include Labels include Exceptionless
end
\end{ocamlcode}
floating nested modules up (Enum.include, etc)
include Enum, will expose all Enum have to the following context, so Enum.Labels
is as Labels, so you can now include Labels, but \emph{Labels.v will override Enum.v},
maybe you want it, and \emph{module Enum still has Enum.Labels.v}, we just duplicated
the nested module into toplevel
\end{itemize}
\end{itemize}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "master"
%%% End: