aboutsummaryrefslogtreecommitdiffhomepage
path: root/notes/decls_comparison.txt
blob: 3ad4ba035b616f08eddd81555377c195906a1347 (plain)
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

Comparison between different syntaxes for declarations
======================================================

Style 1:                    Style 2:                      Style 3:
    int x                   int x                         x: int
    Thing a                 obj Thing a                   a: Thing
    var Thing b             var obj Thing b               b: var Thing

    type T = struct {       type T = struct {             type T = struct {
        int x                   int x                         x: int
        int y                   int y                         y: int
        Thing a                 obj Thing a                   a: Thing
        Thing b                 obj Thing b                   b: Thing
        var Other c             var rec Other c               c: var Other
    }                       }                             }
    func f(Th t) -> Th      func f(obj Th t) -> obj Th    func f(t: Th) -> Th

Style 4:                            Style 5:                Style 6:
    x: int                          int x                   int x
    a: obj Thing                    def Thing a             obj a
    b: var obj Thing                def var Thing b         var obj b

    type T = struct {               type T = struct {       type T = struct {
        x: int                          int x                   int x
        y: int                          int y                   int y
        a: obj Thing                    Thing a                 Thing a
        b: obj Thing                    Thing b                 Thing b
        c: var rec Other                var Other c             var Other c
    }                                }                      }
    func f(t: obj Th) -> obj Th      func f(Th t) -> Th     func f(Th t) -> Th

Style 7: ?

(Style 6 relies on type inference, which is something I don't like)
Also, if style 1,3 and 5 is combined with implicit ref, then it is not clear
whether a defined variable is an object (reference type) or record (not a
reference type).

Style 1:
+ Similar to existing languages
+ Concise
Style 2
+ Logical
+ Simple to parse
Style 3:
+ Concise
Style 4:
+ Logical
Style 5:
+ Logical
Style 6:
+ Concise