-
Notifications
You must be signed in to change notification settings - Fork 14
/
STYLE
executable file
·79 lines (53 loc) · 2.6 KB
/
STYLE
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
Code naming conventions
-----------------------
* Signature names should be in all caps, with underscores separating
words.
* Structure and functor names should be capitalized, with capitals
starting words (a.k.a. camel case).
* Types and terms should begin with a lower-case letter, with capitals
starting following words (a.k.a. camel case).
* Constructors should be capitalized, and may (optionally) be all
caps.
* Type classes (signatures that indicate operations on existing types,
usually to serve as a functor argument) should name the principal
type field "t".
* Multiple implementations of an interface should be named such as
AdjectiveFoo (or AdjectiveFooFun). Thus RedBlackDict, not
DictRedBlack.
File conventions
----------------
* File names should be in all lower case, with hyphens separating
words.
* Files containing only signatures should be named with a ".sig"
suffix. Other files should be named with a ".sml" suffix.
* Multiple implementations of an interface should be given names such
as foo-adjective.sml. Thus, dict-red-black.sml, not
red-black-dict.sml. (Note that this file name convention differs
from the structure/functor name convention. This is to allow
multiple implementions to sort together.)
* Type classes should generally be placed in their own files, rather
than in the same file as a functor that depends on them.
Other conventions
-----------------
* Curried functions are generally preferred to functions taking tupled
arguments.
There are exceptions in which tuples are reasonable, however. For
example:
- One might take arguments in a tuple in order to match the usage in
a similar basis function, such as a comparison function.
- Since SML does not provide a convenient syntax for anonymous
curried functions, a function argument of a higher-order function
might take its arguments in a tuple. (For example, the first
argument to a fold-like operation.)
* Please avoid inexhaustive matches.
* Functor arguments using specification-list notation are preferred to
signature notation. That is, we prefer:
functor FooFun (structure Bar : BAR) = ...
to:
functor FooFun (Bar : BAR) = ...
Several exceptions are grandfathered in, though.
* Adding an operation to a signature is usually not considered an
incompatible change for versioning purposes (even though, strictly
speaking, one could write SML code that depends on its absence).
However, adding an operation to a type class (e.g., ORDERED or
STREAMABLE) is an incompatible change.