File: Test076.ML

package info (click to toggle)
polyml 5.6-8
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 31,892 kB
  • ctags: 34,453
  • sloc: cpp: 44,983; ansic: 24,520; asm: 14,850; sh: 11,730; makefile: 551; exp: 484; python: 253; awk: 91; sed: 9
file content (167 lines) | stat: -rw-r--r-- 2,848 bytes parent folder | download | duplicates (5)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
(* Assorted tests on flexible records.  Some should fail. *)

let
    val f = #a
    val g = #b

    fun h x =
    let
        val i = f x
        and j = g x
    in
        1
    end

    val _ = h {a = 1, b = 2, c = 3}
    val _ = h {a = true, b = [], c = 0.0 }
in
    1
end;


let
    fun f {a, ...} = a
    fun g {a, b} = a
    
    fun h x =
    let
        val i = f x
        and j = g x
    in
        1
    end

in
    1
end;



local
    val f = #a
    val g = #b

    fun h (x as {a, b, ...}) =
    let
        val i = f x
        and j = g x
    in
        1
    end

    val _ = h {a = 1, b = 2, c = 3}
    val _ = h {a = true, b = [], c = 0.0 }
in
    val h = h
end;


(* flexrecord2 *)
val _ =
   let
      val g = #foo
      val _ = g {foo = 13}
      val _ = g {foo = "yes"}
   in
      ()
   end;
(* flexrecord2 *)

(* flexrecord3 *)
val _ =
   let
      val g = #foo
      val _ = g {foo = 13, goo = 1.0}
      val _ = g {foo = "yes", goo = 1.0}
   in
      ()
   end;
(* flexrecord3 *)

(* flexrecord4 *)
val _ =
   let
      val g = #foo
      val _ = g {foo = 13, goo = 1.0}
      val _ = g {foo = "yes", goo = false}
   in
      ()
   end;
(* flexrecord4 *)

local
    val g = #b
    fun f (x as {a, ...}) = if x = x then g x else g x
    val _ = f{a=1, b=0, c = true}
in
    val f = f
end;

let
    fun g (x as {b,...}) = x
    fun i (x as {a,b,...}) =
        g (if true then g x else g {a=2, b = 1, c=3})
in
    1
end;

(* Setting the generic has an effect on an instance constrained by value polymorphism.
   Both foo and bar in g have types which are free variables. *)
local
    val f = #foo
    val g = valOf o f
    val _ = f {foo=0, bar=1}
in
    val f = f and g = g
end;

local
    val f = #foo
    val g = (valOf: int option -> int) o f
    val _ = f {foo=0, bar=1}
in
    val f = f and g = g
end;


local
    val f = #foo
    val g = valOf o f
    val _ = f {foo=0, bar=1}
    val _ = g {foo=SOME 0, bar = true}
in
    val f = f and g = g
end;

(* Check that equality is inherited correctly. The equality attribute is a
   property of the generic as well as the instance.
   In this example the generic instance for g is an equality type but f
   is not. *)
local
    fun f (x as {a, ...}) = (x=x; a)
    fun g {a, ...} = a
    fun h x = (g x; f x)
    val _ = h{a=1, b=2}
in
    val f = f and g = g and h = h
end;


(* In this example it is the INSTANCE which is an equality type. ???? *)
local
    val f = #foo
    fun g x = (x=x; f x)
    val _ = f{foo=0.0, bar=0.0}
in
    val f = f and g = g
end;


(* This demonstrates that the flexible record can be made rigid anywhere
   withing the topdec. *)
structure S = struct val f = #foo end val _ = S.f{foo=1, goo=2};


(* Shows that we can make the record rigid using the signature. *)
structure S : sig val f : {a: 'a, b: 'b} -> 'a end =
struct val f = #a end;