Testsuite: delete Windows line endings [skip ci] (#11631)
[ghc.git] / testsuite / tests / simplCore / should_run / T5441a.hs
1 module T5441a where
2
3 import Unsafe.Coerce (unsafeCoerce)
4 import GHC.Prim (Any)
5
6 listmap :: (a -> b) -> [a] -> [b]
7 listmap f [] = []
8 listmap f (x : xs) = f x : listmap f xs
9
10 data Nat = Z | S Nat
11
12 {-# NOINLINE inject #-}
13 inject :: Nat -> Nat -> Nat
14 inject m i = i
15
16 {-# NOINLINE look #-}
17 look :: Nat -> String -> Char
18 look Z _ = '0'
19
20 showDigit :: Nat -> () -> Nat -> Char
21 showDigit base prf d = look (inject base d) ""
22
23 toDigits :: Nat -> Nat -> [Nat]
24 toDigits Z Z = [Z]
25
26 coe1 :: (Nat -> String) -> Any
27 coe1 = unsafeCoerce
28
29 coe2 :: Any -> (Nat -> String)
30 coe2 = unsafeCoerce
31
32 showInBase :: Nat -> Any
33 showInBase base
34 = coe1 (\n -> listmap
35 (showDigit base ())
36 (toDigits base n))
37
38 showNat :: Nat -> String
39 showNat = coe2 (showInBase Z)