aboutsummaryrefslogtreecommitdiff
path: root/docs/notes/constraints.txt
blob: ddd54e441356e532d9b8538c97ef22a897640939 (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
53


conditions
----------

Should conditions be bound to types, or have a certain scope?

    type conditions:
    
        int cond(value > 0) i = 1;
        
        (float) sqrt(float cond(value >= 0));
        
        () clear(list(T) postcond(value.length == 0));
        
        typedef a = (
            int cond(value > 0) x;
            int y;
        );
        
        typedef a = (
            int x;
            int y;
        ) cond(x > y);
        
        () create_list(count size, count capacity) cond(size <= capacity);
        
    
    statement conditions (more/less flexible? more/less readable?):
        
        int i = 1 cond(value > 0);
        
        typedef a = (
            int x;
            int y;
        ) cond(x > y);
        
        () create_list(count size, count capacity) cond(size <= capacity);
        
    

It's possible to use a value where a constrained type is expected in the
following cases (assuming the type is compatible, apart from it's conditions):

    1) The target type has no conditions.
    
    2) The target type has a weaker (or equally strict) condition as
       the combined condition of the following: 
        a) the source type
        b) the scope
        c) other things that can the compiler can compute easily?