[project @ 2001-08-22 11:45:06 by sewardj]
[ghc-hetmet.git] / ghc / tests / programs / fast2haskell / Main.hs
1 module Main (main) -- TEST
2 where {
3 import Fast2haskell;
4 import Complex;--1.3
5 import Array;--1.3
6
7     c_eps=(5.00000e-06 :: Double);
8     c_t=True;
9     c_f=False;
10     c_input=(0 :: Int);
11     f_main a_n=
12         let { 
13             r_x=[(a_tf,(++) (show a_i) ((++) "\t" a_str))|(a_i,(a_tf,a_str))<-f_zip2 (enumFrom (1 :: Int)) c_testlist];
14             r_noks=[(++) a_str "\n"|(a_tf,a_str)<-r_x,not a_tf];
15             r_oks=[(++) a_str "\n"|(a_tf,a_str)<-r_x,a_tf]
16          } in  
17             if (((>) :: (Int -> Int -> Bool)) a_n (0 :: Int))
18             then (f_onetest ((!!) c_testlist (((-) :: (Int -> Int -> Int)) a_n (1 :: Int))))
19             else 
20                 ((++) (show (length r_oks)) ((++) " tests passed and " ((++) (show 
21                 (length r_noks)) ((++) " failed\n" (c_concat r_noks)))));
22     f_onetest (True,a_str)=(++) "true:  " ((++) a_str "\n");
23     f_onetest (False,a_str)=(++) "false: " ((++) a_str "\n");
24     f_booltest a_name True a_try=
25         if a_try
26         then (True,"")
27         else 
28             (False,(++) a_name "\tok: true is: false");
29     f_booltest a_name False a_try=
30         if (not a_try)
31         then (True,"")
32         else 
33             (False,(++) a_name "\tok: false is: true");
34     f_inttest a_name a_ok a_try=
35         if (((==) :: (Int -> Int -> Bool)) a_ok a_try)
36         then (True,"")
37         else 
38             (False,(++) a_name ((++) "\tok: " ((++) (show a_ok) ((++) "\tis: " 
39             (show a_try)))));
40     f_chartest a_name a_ok a_try=
41         if (((==) :: (Int -> Int -> Bool)) (fromEnum a_ok) (fromEnum a_try))
42         then (True,"")
43         else 
44             (False,(++) a_name ((++) "\tok: " ((++) ((:) a_ok []) ((++) "\tis: " 
45             ((:) a_try [])))));
46     f_strtest a_name a_ok a_try=
47         if (strcmp a_ok a_try)
48         then (True,"")
49         else 
50             (False,(++) a_name ((++) "\tok: " ((++) a_ok ((++) "\tis: " a_try))));
51     f_linttest a_name a_ok a_try=
52         if (f_lintcmp a_ok a_try)
53         then (True,"")
54         else 
55             (False,(++) a_name ((++) "\tok: " ((++) (f_showlint a_ok) ((++) "\tis: " 
56             (f_showlint a_try)))));
57     f_doubtest a_name a_ok a_try=
58         if (((<=) :: (Double -> Double -> Bool)) (f_abs (((-) :: (Double -> Double -> Double)) a_ok a_try)) c_eps)
59         then (True,"")
60         else 
61             (False,(++) a_name ((++) "\tok: " ((++) (show a_ok) ((++) "\tis: " 
62             ((++) (show a_try) ((++) "\tok-is: " (show (((-) :: (Double -> Double -> Double)) a_ok a_try))))))));
63     f_alternating a_l=(:) (0 :: Int) ((:) (1 :: Int) a_l);
64     f_showlint []=[];
65     f_showlint a_xs=tail (c_concat [(++) "," (show a_x)|a_x<-a_xs]);
66     f_lintcmp [] []=True;
67     f_lintcmp [] a_ys=False;
68     f_lintcmp a_xs []=False;
69     f_lintcmp (a_x:a_xs) (a_y:a_ys)=
70         if (((==) :: (Int -> Int -> Bool)) a_x a_y)
71         then (f_lintcmp a_xs a_ys)
72         else 
73             False;
74     c_testlist=(:) (f_inttest "array" (10 :: Int) ((!) (array (descr (1 :: Int) (3 :: Int)) ((:) 
75         ((,) (3 :: Int) (30 :: Int)) ((:) ((,) (1 :: Int) (10 :: Int)) ((:) ((,) (2 :: Int) (20 :: Int)) [])))) (1 :: Int))) ((:) (f_inttest "array" (20 :: Int) 
76         ((!) (array (descr (1 :: Int) (3 :: Int)) ((:) ((,) (3 :: Int) (30 :: Int)) ((:) ((,) (1 :: Int) (10 :: Int)) 
77         ((:) ((,) (2 :: Int) (20 :: Int)) [])))) (2 :: Int))) ((:) (f_inttest "array" (30 :: Int) ((!) (array (descr (1 :: Int) (3 :: Int)) 
78         ((:) ((,) (3 :: Int) (30 :: Int)) [])) (3 :: Int))) ((:) (f_inttest "assoc" (0 :: Int) (indassoc ((,) (0 :: Int) (1 :: Int)))) ((:) 
79         (f_inttest "assoc" (1 :: Int) (valassoc ((,) (0 :: Int) (1 :: Int)))) ((:) (f_inttest "bounds" (1 :: Int) (lowbound (bounds 
80         (listArray (descr (1 :: Int) (3 :: Int)) ((:) (1 :: Int) ((:) (2 :: Int) ((:) (3 :: Int) []))))))) ((:) (f_inttest "bounds" (3 :: Int) 
81         (upbound (bounds (listArray (descr (1 :: Int) (3 :: Int)) ((:) (1 :: Int) ((:) (2 :: Int) ((:) (3 :: Int) []))))))) 
82         ((:) (f_inttest "descr" (0 :: Int) (lowbound (descr (0 :: Int) (1 :: Int)))) ((:) (f_inttest "descr" (1 :: Int) (upbound 
83         (descr (0 :: Int) (1 :: Int)))) ((:) (f_linttest "destr_update" ((:) (1 :: Int) ((:) (0 :: Int) ((:) (3 :: Int) []))) (elems 
84         (destr_update (listArray (descr (0 :: Int) (2 :: Int)) ((:) (1 :: Int) ((:) (2 :: Int) ((:) (3 :: Int) [])))) (1 :: Int) (0 :: Int)))) ((:) 
85         (f_linttest "destr_update" ((:) (0 :: Int) []) (elems (destr_update (listArray (descr (0 :: Int) (0 :: Int)) ((:) (1 :: Int) 
86         ((:) (2 :: Int) ((:) (3 :: Int) [])))) (0 :: Int) (0 :: Int)))) ((:) (f_linttest "elems" ((:) (1 :: Int) ((:) (2 :: Int) ((:) (3 :: Int) []))) 
87         (elems (listArray (descr (0 :: Int) (2 :: Int)) ((:) (1 :: Int) ((:) (2 :: Int) ((:) (3 :: Int) [])))))) ((:) 
88         (f_linttest "elems" ((:) (1 :: Int) []) (elems (listArray (descr (0 :: Int) (0 :: Int)) ((:) (1 :: Int) ((:) (2 :: Int) 
89         ((:) (3 :: Int) [])))))) ((:) (f_inttest "indassoc" (0 :: Int) (indassoc ((,) (0 :: Int) (1 :: Int)))) ((:) (f_linttest "listarray" 
90         ((:) (1 :: Int) ((:) (2 :: Int) ((:) (3 :: Int) []))) (elems (listArray (descr (0 :: Int) (2 :: Int)) ((:) (1 :: Int) 
91         ((:) (2 :: Int) ((:) (3 :: Int) [])))))) ((:) (f_linttest "listarray" ((:) (1 :: Int) []) (elems (listArray 
92         (descr (0 :: Int) (0 :: Int)) ((:) (1 :: Int) ((:) (2 :: Int) ((:) (3 :: Int) [])))))) ((:) (f_inttest "lowbound" (0 :: Int) (lowbound 
93         (descr (0 :: Int) (1 :: Int)))) ((:) (f_inttest "subscript" (1 :: Int) ((!) (tabulate ((!!) ((:) (1 :: Int) 
94         ((:) (2 :: Int) ((:) (3 :: Int) [])))) (descr (0 :: Int) (2 :: Int))) (0 :: Int))) ((:) (f_inttest "subscript" (2 :: Int) ((!) (tabulate 
95         ((!!) ((:) (1 :: Int) ((:) (2 :: Int) ((:) (3 :: Int) [])))) (descr (0 :: Int) (2 :: Int))) (1 :: Int))) ((:) (f_inttest "subscript" (3 :: Int) 
96         ((!) (tabulate ((!!) ((:) (1 :: Int) ((:) (2 :: Int) ((:) (3 :: Int) [])))) (descr (0 :: Int) (2 :: Int))) (2 :: Int))) 
97         ((:) (f_linttest "tabulate" ((:) (1 :: Int) ((:) (2 :: Int) ((:) (3 :: Int) []))) (elems (tabulate 
98         ((!!) ((:) (1 :: Int) ((:) (2 :: Int) ((:) (3 :: Int) [])))) (descr (0 :: Int) (2 :: Int))))) ((:) (f_linttest "tabulate" 
99         ((:) (1 :: Int) []) (elems (tabulate ((!!) ((:) (1 :: Int) ((:) (2 :: Int) ((:) (3 :: Int) [])))) 
100         (descr (0 :: Int) (0 :: Int))))) ((:) (f_inttest "upbound" (1 :: Int) (upbound (descr (0 :: Int) (1 :: Int)))) ((:) (f_inttest "valassoc" (1 :: Int) 
101         (valassoc ((,) (0 :: Int) (1 :: Int)))) ((:) (f_doubtest "add_x" (0.00000 :: Double) (realPart (((+) :: (Complex_type -> Complex_type -> Complex_type)) ((:+) (0.00000 :: Double) (0.00000 :: Double)) 
102         ((:+) (0.00000 :: Double) (0.00000 :: Double))))) ((:) (f_doubtest "add_x" (0.00000 :: Double) (imagPart (((+) :: (Complex_type -> Complex_type -> Complex_type)) ((:+) (0.00000 :: Double) (0.00000 :: Double)) ((:+) (0.00000 :: Double) (0.00000 :: Double))))) 
103         ((:) (f_doubtest "add_x" (4.00000 :: Double) (realPart (((+) :: (Complex_type -> Complex_type -> Complex_type)) ((:+) (1.00000 :: Double) (2.00000 :: Double)) ((:+) (3.00000 :: Double) (4.00000 :: Double))))) ((:) 
104         (f_doubtest "add_x" (6.00000 :: Double) (imagPart (((+) :: (Complex_type -> Complex_type -> Complex_type)) ((:+) (1.00000 :: Double) (2.00000 :: Double)) ((:+) (3.00000 :: Double) (4.00000 :: Double))))) ((:) (f_doubtest "complex" (1.00000 :: Double) 
105         (realPart ((:+) (1.00000 :: Double) (0.00000 :: Double)))) ((:) (f_doubtest "complex" (1.00000 :: Double) (imagPart ((:+) (0.00000 :: Double) (1.00000 :: Double)))) ((:) 
106         (f_doubtest "complex_im" (0.00000 :: Double) (imagPart ((:+) (1.00000 :: Double) (0.00000 :: Double)))) ((:) (f_doubtest "complex_im" (1.00000 :: Double) (imagPart ((:+) (0.00000 :: Double) (1.00000 :: Double)))) 
107         ((:) (f_doubtest "complex_re" (0.00000 :: Double) (realPart ((:+) (0.00000 :: Double) (1.00000 :: Double)))) ((:) (f_doubtest "complex_re" (1.00000 :: Double) (realPart 
108         ((:+) (1.00000 :: Double) (0.00000 :: Double)))) ((:) (f_doubtest "mul_x" (0.00000 :: Double) (realPart (((*) :: (Complex_type -> Complex_type -> Complex_type)) ((:+) (0.00000 :: Double) (0.00000 :: Double)) ((:+) (0.00000 :: Double) (0.00000 :: Double))))) 
109         ((:) (f_doubtest "mul_x" (0.00000 :: Double) (imagPart (((*) :: (Complex_type -> Complex_type -> Complex_type)) ((:+) (0.00000 :: Double) (0.00000 :: Double)) ((:+) (0.00000 :: Double) (0.00000 :: Double))))) ((:) 
110         (f_doubtest "mul_x" (((negate) :: (Double -> Double)) (5.00000 :: Double)) (realPart (((*) :: (Complex_type -> Complex_type -> Complex_type)) ((:+) (1.00000 :: Double) (2.00000 :: Double)) ((:+) (3.00000 :: Double) (4.00000 :: Double))))) ((:) 
111         (f_doubtest "mul_x" (10.0000 :: Double) (imagPart (((*) :: (Complex_type -> Complex_type -> Complex_type)) ((:+) (1.00000 :: Double) (2.00000 :: Double)) ((:+) (3.00000 :: Double) (4.00000 :: Double))))) ((:) (f_doubtest "sub_x" (0.00000 :: Double) 
112         (realPart (((-) :: (Complex_type -> Complex_type -> Complex_type)) ((:+) (0.00000 :: Double) (0.00000 :: Double)) ((:+) (0.00000 :: Double) (0.00000 :: Double))))) ((:) (f_doubtest "sub_x" (0.00000 :: Double) (imagPart 
113         (((-) :: (Complex_type -> Complex_type -> Complex_type)) ((:+) (0.00000 :: Double) (0.00000 :: Double)) ((:+) (0.00000 :: Double) (0.00000 :: Double))))) ((:) (f_doubtest "sub_x" (((negate) :: (Double -> Double)) (2.00000 :: Double)) (realPart 
114         (((-) :: (Complex_type -> Complex_type -> Complex_type)) ((:+) (1.00000 :: Double) (2.00000 :: Double)) ((:+) (3.00000 :: Double) (4.00000 :: Double))))) ((:) (f_doubtest "sub_x" (((negate) :: (Double -> Double)) (2.00000 :: Double)) (imagPart 
115         (((-) :: (Complex_type -> Complex_type -> Complex_type)) ((:+) (1.00000 :: Double) (2.00000 :: Double)) ((:+) (3.00000 :: Double) (4.00000 :: Double))))) ((:) (f_inttest "seq" (2 :: Int) (seq (enumFrom (1 :: Int)) (2 :: Int))) 
116         ((:) (f_strtest "**" "this one" "should fail") [])))))))))))))))))))))))))))))))))))))))))));
117     f_abs a_x=
118         if (((<=) :: (Double -> Double -> Bool)) a_x (0.00000 :: Double))
119         then (((negate) :: (Double -> Double)) a_x)
120         else 
121             a_x;
122     c_and=f_foldr (&&) True;
123     f_cjustify a_n a_s=
124         let { 
125             r_margin=((-) :: (Int -> Int -> Int)) a_n (length a_s);
126             r_lmargin=((div) :: (Int -> Int -> Int)) r_margin (2 :: Int);
127             r_rmargin=((-) :: (Int -> Int -> Int)) r_margin r_lmargin
128          } in  (++) (f_spaces r_lmargin) ((++) a_s (f_spaces r_rmargin));
129     c_concat=f_foldr (++) [];
130     f_const a_x a_y=a_x;
131     f_digit a_x=
132         if (((<=) :: (Int -> Int -> Bool)) (fromEnum '0') (fromEnum a_x))
133         then (((<=) :: (Int -> Int -> Bool)) (fromEnum a_x) (fromEnum '9'))
134         else 
135             False;
136     f_drop 0 a_x=a_x;
137     f_drop a_n (a_a:a_x)=f_drop (((-) :: (Int -> Int -> Int)) a_n (1 :: Int)) a_x;
138     f_drop a_n a_x=[];
139     f_dropwhile a_f []=[];
140     f_dropwhile a_f (a_a:a_x)=
141         if (a_f a_a)
142         then (f_dropwhile a_f a_x)
143         else 
144             ((:) a_a a_x);
145     c_e=((exp) :: (Double -> Double)) (1.00000 :: Double);
146     f_filter a_f a_x=[a_a|a_a<-a_x,a_f a_a];
147     f_foldl a_op a_r []=a_r;
148     f_foldl a_op a_r (a_a:a_x)=
149         let { 
150             f_strict a_f a_x=seq a_x (a_f a_x)
151          } in  f_foldl a_op (f_strict a_op a_r a_a) a_x;
152     f_foldl1 a_op (a_a:a_x)=f_foldl a_op a_a a_x;
153     f_foldr a_op a_r []=a_r;
154     f_foldr a_op a_r (a_a:a_x)=a_op a_a (f_foldr a_op a_r a_x);
155     f_foldr1 a_op (a_a:[])=a_a;
156     f_foldr1 a_op (a_a:a_b:a_x)=a_op a_a (f_foldr1 a_op ((:) a_b a_x));
157     f_fst (a_a,a_b)=a_a;
158     f_id a_x=a_x;
159     f_index a_x=
160         let { 
161             f_f a_n []=[];
162             f_f a_n (a_a:a_x)=(:) a_n (f_f (((+) :: (Int -> Int -> Int)) a_n (1 :: Int)) a_x)
163          } in  f_f (0 :: Int) a_x;
164     f_init (a_a:a_x)=
165         if (null a_x)
166         then []
167         else 
168             ((:) a_a (f_init a_x));
169     f_iterate a_f a_x=(:) a_x (f_iterate a_f (a_f a_x));
170     f_last a_x=(!!) a_x (((-) :: (Int -> Int -> Int)) (length a_x) (1 :: Int));
171     f_lay []=[];
172     f_lay (a_a:a_x)=(++) a_a ((++) "\n" (f_lay a_x));
173     f_layn a_x=
174         let { 
175             f_f a_n []=[];
176             f_f a_n (a_a:a_x)=(++) (f_rjustify (4 :: Int) (show a_n)) ((++) ") " ((++) a_a ((++) "\n" 
177                 (f_f (((+) :: (Int -> Int -> Int)) a_n (1 :: Int)) a_x))))
178          } in  f_f (1 :: Int) a_x;
179     f_letter a_c=
180         if (
181             if (((<=) :: (Int -> Int -> Bool)) (fromEnum 'a') (fromEnum a_c))
182             then (((<=) :: (Int -> Int -> Bool)) (fromEnum a_c) (fromEnum 'z'))
183             else 
184                 False)
185         then True
186         else 
187         if (((<=) :: (Int -> Int -> Bool)) (fromEnum 'A') (fromEnum a_c))
188         then (((<=) :: (Int -> Int -> Bool)) (fromEnum a_c) (fromEnum 'Z'))
189         else 
190             False;
191     f_limit (a_a:a_b:a_x)=
192         if (((==) :: (Double -> Double -> Bool)) a_a a_b)
193         then a_a
194         else 
195             (f_limit ((:) a_b a_x));
196     f_lines []=[];
197     f_lines (a_a:a_x)=
198         let { 
199             r_xs=
200                 if (pair a_x)
201                 then (f_lines a_x)
202                 else 
203                     ((:) [] [])
204          } in  
205             if (((==) :: (Int -> Int -> Bool)) (fromEnum a_a) (fromEnum '\o012'))
206             then ((:) [] (f_lines a_x))
207             else 
208                 ((:) ((:) a_a (head r_xs)) (tail r_xs));
209     f_ljustify a_n a_s=(++) a_s (f_spaces (((-) :: (Int -> Int -> Int)) a_n (length a_s)));
210     f_map a_f a_x=[a_f a_a|a_a<-a_x];
211     f_map2 a_f a_x a_y=[a_f a_a a_b|(a_a,a_b)<-f_zip2 a_x a_y];
212     f_max a_xs=f_foldl1 f_max2 a_xs;
213     f_max2 a_a a_b=
214         if (((>=) :: (Int -> Int -> Bool)) a_a a_b)
215         then a_a
216         else 
217             a_b;
218     f_member a_x a_a=c_or (f_map (flip ((==) :: (Int -> Int -> Bool)) a_a) a_x);
219     f_merge [] a_y=a_y;
220     f_merge (a_a:a_x) []=(:) a_a a_x;
221     f_merge (a_a:a_x) (a_b:a_y)=
222         if (((<=) :: (Int -> Int -> Bool)) a_a a_b)
223         then ((:) a_a (f_merge a_x ((:) a_b a_y)))
224         else 
225             ((:) a_b (f_merge ((:) a_a a_x) a_y));
226     f_min a_xs=f_foldl1 f_min2 a_xs;
227     f_min2 a_a a_b=
228         if (((>) :: (Int -> Int -> Bool)) a_a a_b)
229         then a_b
230         else 
231             a_a;
232     f_mkset []=[];
233     f_mkset (a_a:a_x)=(:) a_a (f_filter (flip ((/=) :: (Int -> Int -> Bool)) a_a) (f_mkset a_x));
234     c_or=f_foldr (||) False;
235     c_pi=((*) :: (Double -> Double -> Double)) (4.00000 :: Double) (((atan) :: (Double -> Double)) (1.00000 :: Double));
236     f_postfix a_a a_x=(++) a_x ((:) a_a []);
237     c_product=f_foldl ((*) :: (Int -> Int -> Int)) (1 :: Int);
238     f_rep a_n a_x=f_take a_n (f_repeat a_x);
239     f_repeat a_x=(:) a_x (f_repeat a_x);
240     c_reverse=f_foldl (flip (:)) [];
241     f_rjustify a_n a_s=(++) (f_spaces (((-) :: (Int -> Int -> Int)) a_n (length a_s))) a_s;
242     f_scan a_op=
243         let { 
244             f_g a_r []=(:) a_r [];
245             f_g a_r (a_a:a_x)=(:) a_r (f_g (a_op a_r a_a) a_x)
246          } in  f_g;
247     f_snd (a_a,a_b)=a_b;
248     f_sort a_x=
249         let { 
250             r_n=length a_x;
251             r_n2=((div) :: (Int -> Int -> Int)) r_n (2 :: Int)
252          } in  
253             if (((<=) :: (Int -> Int -> Bool)) r_n (1 :: Int))
254             then a_x
255             else 
256                 (f_merge (f_sort (f_take r_n2 a_x)) (f_sort (f_drop r_n2 a_x)));
257     f_spaces a_n=f_rep a_n ' ';
258     f_subtract a_x a_y=((-) :: (Int -> Int -> Int)) a_y a_x;
259     c_sum=f_foldl ((+) :: (Int -> Int -> Int)) (0 :: Int);
260 data 
261     T_sys_message=F_Stdout [Char] | F_Stderr [Char] | F_Tofile [Char] [Char] | F_Closefile [Char] | F_Appendfile [Char] | F_System [Char] | F_Exit Int;
262     f_take 0 a_x=[];
263     f_take a_n (a_a:a_x)=(:) a_a (f_take (((-) :: (Int -> Int -> Int)) a_n (1 :: Int)) a_x);
264     f_take a_n a_x=[];
265     f_takewhile a_f []=[];
266     f_takewhile a_f (a_a:a_x)=
267         if (a_f a_a)
268         then ((:) a_a (f_takewhile a_f a_x))
269         else 
270             [];
271     f_transpose a_x=
272         let { 
273             r_x'=f_takewhile pair a_x
274          } in  
275             if (null r_x')
276             then []
277             else 
278                 ((:) (f_map head r_x') (f_transpose (f_map tail r_x')));
279     f_until a_f a_g a_x=
280         if (a_f a_x)
281         then a_x
282         else 
283             (f_until a_f a_g (a_g a_x));
284     f_zip2 (a_a:a_x) (a_b:a_y)=(:) (a_a,a_b) (f_zip2 a_x a_y);
285     f_zip2 a_x a_y=[];
286     f_zip3 (a_a:a_x) (a_b:a_y) (a_c:a_z)=(:) (a_a,a_b,a_c) (f_zip3 a_x a_y a_z);
287     f_zip3 a_x a_y a_z=[];
288     f_zip4 (a_a:a_w) (a_b:a_x) (a_c:a_y) (a_d:a_z)=(:) (a_a,a_b,a_c,a_d) (f_zip4 a_w a_x a_y a_z);
289     f_zip4 a_w a_x a_y a_z=[];
290     f_zip5 (a_a:a_v) (a_b:a_w) (a_c:a_x) (a_d:a_y) (a_e:a_z)=(:) (a_a,a_b,a_c,a_d,a_e) (f_zip5 a_v a_w a_x a_y a_z);
291     f_zip5 a_v a_w a_x a_y a_z=[];
292     f_zip6 (a_a:a_u) (a_b:a_v) (a_c:a_w) (a_d:a_x) (a_e:a_y) (a_f:a_z)=(:) (a_a,a_b,a_c,a_d,a_e,a_f) (f_zip6 a_u a_v a_w a_x a_y a_z);
293     f_zip6 a_u a_v a_w a_x a_y a_z=[];
294     f_zip (a_x,a_y)=f_zip2 a_x a_y;
295     main = putStr (f_main c_input)
296 }