Update Trac ticket URLs to point to GitLab
[ghc.git] / testsuite / tests / codeGen / should_run / cgrun058.hs
1 -- Not really a code-gen test, but this program gave
2 -- incorrect results in Hugs (Hugs #37), so I
3 -- thought I'd add it to GHC's test suite.
4
5 module Main where
6
7 data MInt = Zero | Succ MInt | Pred MInt deriving Show
8
9 tn :: Int -> MInt
10 tn x | x<0 = Pred (tn (x+1))
11 tn 0 = Zero
12 tn n = Succ (tn (n - 1))
13
14 ti :: MInt -> Int
15 ti Zero = 0
16 ti (Succ x) = 1+(ti x)
17 ti (Pred x) = (ti x) -1
18
19 testi :: (MInt -> MInt -> MInt) -> (Int -> Int -> Int) -> Int -> Int -> Bool
20 testi f g x y = (ti (f (tn x) (tn y))) /= (g x y)
21
22 myMul x y = tn ((ti x) * (ti y))
23
24 -- test should be empty!
25 test = [ (x,y,ti (myMul (tn x) (tn y)),x * y)
26 | x<-[-100, -99, -98, -97, -2, -1, 0, 1, 2, 97, 98, 99, 100],
27 y<-([-100..(-1)]++[1..100]),
28 testi myMul (*) x y ]
29
30 main = print test