Test.ml 1.26 KB
Newer Older
charguer's avatar
charguer committed
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



let f0 () =
  let r = ref [] in
  !r

let f1 () : 'a list =
  let r = ref ([] : 'a list) in
  !r

let f2 () =
  let r : ('a ref) = ref [] in
  !r

let f3 () =
  let r : (int list) ref = ref [] in
  !r

let f4 () =
  let r = ref ([] : int list) in
  !r


let g1 () : 'a list =
  let r = ref [] in
  r := [5];
  !r

let g2 () =
  let r : ('a list) ref = ref [] in
  r := [4];
  !r

let m0 () =
   let r = ref [] in
   r

let h0 () =
  let g =
     let f () = ref [] in
     f in
  g

(* not allowed because produces a ['_a list ref] at top level;
   i.e. rejected when using OCaml "-strict_value_restriction" flag 
let h1 =
  let f () : 'a list ref = ref [] in
  f
*)

let h2 () =
  let f () : 'a list ref = ref [] in
  f

let h3 () =
  let f () = ref [] in
  f()


let k1 () =
  []

let k2 () =
  ref []

(* CF does not typecheck because the type cannot be resolved 

let r1 () =
   let _x = ref [] in
   ()
*)   

(* CF does not typecheck because the type cannot be resolved 

let r2 () =
   let _x = ref [] in
   let y = [] in
   y

*)

type 'a sitems = {
  mutable nb : int;
  mutable items : 'a list; }

let sitems_build n =
  { nb = n; items = [] }

let sitems_incr_nb_let r =
  let x = r.nb in
  r.nb <- x + 1 

let sitems_length_items_let r =
  let x = r.items in
  List.length x