aboutsummaryrefslogtreecommitdiffhomepage
path: root/notes/type_from_identifier.txt
blob: 829259d4d8bc7d54e7a1d256a88e543394787421 (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

Types from identifiers
======================

Here's a way of "manually inferring" the type from identifiers. It can be
useful if identical identifier declarations appear over and over again.

    autotype token = Token
    autotype x = int
    autotype y = int
    autotype input = InputStream
    autotype p0 = [2]int
    autotype p1 = [2]int


    func sum(x, y) -> int
    {
        return x + y
    }

    func parse(arena, input)
    {
        ...
        ref token = .next_from_stream(input)
        ...
    }

    func calculate_location(p0, x)
    {
        # no point in abbreviating built-in types such as "int" to "let"
        int y
        ...
        [] p1 = [1,2]
        ...
    }