1+ type T () =
2+ member this.H <[< Measure >] 'u > ( x : int < 'u >) = x
3+
4+ member this.F <[< Measure >] 'u > ( x : int < 'u >) =
5+ let g x =
6+ this.H x
7+
8+ g x
9+
10+ [<Measure>] type M
11+
12+ type TheType = { A: int ; B: int ; D: int ; G: seq < int > } with
13+ static member Create a b _ d _ _ g = { A= a; B= b; D= d; G= g}
14+
15+ let CreateBadImageFormatException () =
16+ let create a b c d ( e : int < _ >) ( f : int ) g = TheType.Create a b( int c) d e f g
17+ seq { yield create0 0 0 0 0 0 [ 0 ] }
18+
19+ module TestLibrary =
20+
21+ [<Measure>]
22+ type unit =
23+ //converts an integer into a unit of measureof type int<seconds>
24+ static member convertLP x = LanguagePrimitives.Int32WithMeasure x
25+ static member convert x = x* 1 < unit>
26+ static member convertFromInt ( x : int ) = x* 1 < unit> //not generic
27+
28+
29+ //add a unit of measure to a number and convert it back again
30+ let test1 num =
31+ let output = unit.convertLP( num)
32+ int output
33+ let test2 num =
34+ let output = unit.convert( num)
35+ int output
36+
37+
38+ //convert the number in a sub function
39+ let test3 num =
40+ let convert i =
41+ unit.convertLP( i)
42+ let output = convert num//BadImageFormatException is thrown here
43+ int output//type of output inferred as int ?!
44+
45+ let test4 num =
46+ let convert ( i : int ) = //type of i is specified
47+ unit.convertLP( i)
48+ let output = convert num//BadImageFormatException is thrown here
49+ int output//type of output inferred as int ?!
50+
51+ let test5 num = //type of num is inferred as int<u'> but no compile errors are reported
52+ let convert i =
53+ unit.convert( i)
54+ let output = convert num//BadImageFormatException is thrown here
55+ int output
56+
57+ let test6 ( num : int ) =
58+ let convert i = //inference looks incorrect
59+ unit.convert( i)
60+ let output = convert num//BadImageFormatException is thrown here
61+ int output
62+
63+
64+ //two work arounds to the problem
65+ let test7 num =
66+ let convert ( i : int ) = //with the type specified here, this doesn't crash
67+ unit.convert( i)
68+ let output = convert num
69+ int output
70+
71+ let test8 num =
72+ let convert i =
73+ unit.convertFromInt( i) //with the type specified in the converter no exception
74+ let output = convert num
75+ int output
76+
77+
78+ printfn" test 1:%i " ( test11000 )
79+ printfn" test 2:%i " ( test21000 )
80+ printfn" test 3:%i " ( test31000 )
81+ printfn" test 4:%i " ( test41000 )
82+ printfn" test 5:%i " ( test51000 )
83+ printfn" test 6:%i " ( test61000 )
84+ printfn" test 7:%i " ( test71000 )
85+ printfn" test 8:%i " ( test81000 )
86+
87+
88+ [<EntryPoint>]
89+ let main argv =
90+ // test1
91+ let _ = T() .F( LanguagePrimitives.Int32WithMeasure< M> 0 )
92+ // test2
93+ for _ in CreateBadImageFormatException() do ()
94+
95+ System.IO.File.WriteAllText( " test.ok" , " ok" );
96+
97+ 0